我有数组"A"的值:
101 101
0 0
61.6320000000000 0.725754779522671
73.7000000000000 0.830301150185882
78.2800000000000 0.490917508345341
81.2640000000000 0.602561200211232
82.6880000000000 0.435568593909153
Run Code Online (Sandbox Code Playgroud)
我希望删除第一行并保留数组的形状(2列),从而创建数组
0 0
61.6320000000000 0.725754779522671
73.7000000000000 0.830301150185882
78.2800000000000 0.490917508345341
81.2640000000000 0.602561200211232
82.6880000000000 0.435568593909153
Run Code Online (Sandbox Code Playgroud)
我已经使用过A = A(A~=101);,它会根据需要删除值 - 但是它会将数组打包到一列.
我希望我的代码从包含重复项的现有ArrayList(pinyinArrayList)创建一个独特项的ArrayList(uniquePinyinArrayList).
"println"命令不执行(我认为他们应该在来自pinyinArrayList的副本在uniquePinyinArrayList中找到)
fun uniquePinyinArray(pinyinArrayList: ArrayList<String>) {
val uniquePinyinArrayList = ArrayList<String>()
for(currentPinyin in pinyinArrayList){
if (currentPinyin in uniquePinyinArrayList){
// do nothing
println("already contained"+currentPinyin)
println("uniquePinyin"+uniquePinyinArrayList)
}
else {
uniquePinyinArrayList.add(currentPinyin)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我也试过了
if (uniquePinyinArrayList.contains(currentPinyin)){
Run Code Online (Sandbox Code Playgroud)
,虽然这也行不通.
编辑:这个方法实际上是从我的源词列表中为每个单词运行的,因此创建了多个ArrayLists.为了解决这个问题,我在这个循环之外为uniquePinyin创建了一个ArrayList对象.事情现在按预期工作!
这是我的示例代码,用于解决while当满足三个条件中的任何一个时如何结束循环.
我希望代码结束时n = 100,但它结束于n = 301.我怎样才能结束这个n=100?
clear all; close all;
n = 0;
R = 0; A = 0; T = 0;
while (R~=1) || (A~=1) || (T~=1)
if n == 100
R = 1;
end
if n == 200
A = 1;
end
if n == 300
T = 1;
end
n=n+1;
end
Run Code Online (Sandbox Code Playgroud) 我一直在写这样的代码:
index = 0
while (index < 10){
// do something
index ++
}
Run Code Online (Sandbox Code Playgroud)
我想让这个更干净,有一些类似的东西
while(var index = 0; index < 10; index ++)
{
// do something
index ++
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?