Cell array construction operator

8 views (last 30 days)
Yro
Yro on 27 Dec 2020
Answered: Jan on 30 Dec 2020
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.

Answers (1)

Jan
Jan on 30 Dec 2020
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.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!