Anyone know why I am recieving this error?

1 回表示 (過去 30 日間)
Cem SARIKAYA
Cem SARIKAYA 2018 年 12 月 28 日
コメント済み: Image Analyst 2018 年 12 月 28 日
z=1;
m=1;
at = 1;
data = rand(7004829, 1);
for k = 2 : at : length(data)
if k ~= (k+1)
index1=k;
y(m,1) = data(index1:z);
z = k;
m = m+1;
end
end
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 12 月 28 日
Please do not close questions that have an Answer.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2018 年 12 月 28 日
This is also useless:
if k ~= (k+1)
Can you tell me when k will EVER be equal to k+1? Answer: never. So the condition is always true. That wouldn't cause an error though - it's just bad programming.
Also, id, when you do get around to defining it. Must be a 2-D matrix.
And you might want to preallocate y in advance, though it's not necessary.
And finally, there are no comments. All professional programmers put comments in their code to help them understand later what they did, or to help others understand what they did. I don't really know what you're trying to do. Maybe there is a function or one vectorized line of code to do it, but since there are no comments, I don't know.
  3 件のコメント
Walter Roberson
Walter Roberson 2018 年 12 月 28 日
image analyst: redefine length as uint8(255). when k reaches uint(255) then k~=k+1 would be false.
... it could happen !
Image Analyst
Image Analyst 2018 年 12 月 28 日
Walter - true. Cem, if you just want to extract matrices that have only the ID number and no other numbers except zero where that number is not the desired number, you can see this example:
m = randi(3, 4, 6) % Sample ID array
m1 = double(ismember(m, 1)) % Get just the 1's
m2 = 2 * double(ismember(m, 2)) % Get just the 2's
m3 = 3 * double(ismember(m, 3)) % Get just the 3's
You'll see
m =
1 1 2 1 3 2
1 1 3 2 3 2
1 2 3 3 2 1
1 3 2 3 3 2
m1 =
1 1 0 1 0 0
1 1 0 0 0 0
1 0 0 0 0 1
1 0 0 0 0 0
m2 =
0 0 2 0 0 2
0 0 0 2 0 2
0 2 0 0 2 0
0 0 2 0 0 2
m3 =
0 0 0 0 3 0
0 0 3 0 3 0
0 0 3 3 0 0
0 3 0 3 3 0
Is that what you're hoping to do?

サインインしてコメントする。

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 12 月 28 日
編集済み: madhan ravi 2018 年 12 月 28 日
  • id is not defined
  • if condition is superfluos though , always k is not equal to k + 1
  • y needs to be preallocated
  • y can be preallocate as a cell to further avoid error ( unable to perform ....due to size)
  2 件のコメント
Cem SARIKAYA
Cem SARIKAYA 2018 年 12 月 28 日
編集済み: Cem SARIKAYA 2018 年 12 月 28 日
is matlab work concurrent assignment? i need this code not concurrent assignment like c++, and i fix id
madhan ravi
madhan ravi 2018 年 12 月 28 日

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by