Cell array construction operator
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Jan
il 30 Dic 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 Commenti
Vedere anche
Categorie
Scopri di più su Octave in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!