Cell array construction operator
4 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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.
0 Comments
See Also
Categories
Find more on Octave in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!