Cell array construction operator

6 次查看(过去 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 CenterFile Exchange 中查找有关 Octave 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by