Cell array construction operator

4 ビュー (過去 30 日間)
Yro
Yro 2020 年 12 月 27 日
回答済み: Jan 2020 年 12 月 30 日
I want to use GNU Octave to run my simulation but I have the following problem with the following array,
for i = 1:length(ARRAY)
find_fcn1{i,:} = find(ARRAY(:,1)==(ARRAY(i,1) + 1));
find_fcn2{i,:} = find(ARRAY(:,2)==(ARRAY(i,2) + 1));
find_fcn3{i,:} = find(ARRAY(:,1)==(ARRAY(i,1) - 1));
find_fcn4{i,:} = find(ARRAY(:,2)==(ARRAY(i,2) - 1));
end
I get the following error when using Octave: <invalid dimension inquiry of a non-existent value>. How can I modify the cell array to be able to use Octave?.
Thanks in advance.

回答 (1 件)

Jan
Jan 2020 年 12 月 30 日
Did you pre-allocate the cells before the loop?
n = length(ARRAY);
find_fcn1 = cell(n, 1);
find_fcn2 = cell(n, 1);
find_fcn3 = cell(n, 1);
find_fcn4 = cell(n, 1);
for i = 1:n
find_fcn1{i} = find(ARRAY(:,1)==(ARRAY(i,1) + 1));
find_fcn2{i} = find(ARRAY(:,2)==(ARRAY(i,2) + 1));
find_fcn3{i} = find(ARRAY(:,1)==(ARRAY(i,1) - 1));
find_fcn4{i} = find(ARRAY(:,2)==(ARRAY(i,2) - 1));
end
If this is working, the problem was hidden in "find_fcn1{i,:}": If this cell is not defined already, Ocatve cannot guess, how large the 2nd. dimension is. Because find() replies a vector, a "find_fcn1{i, 1}" would be sufficient also.

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by