error with changing array size in loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a loop running as follows:
..............................................................................................................................................
for i= 1:10
if isempty( arr) )==0
for j=1:3
c(:,j)=splitapply(@mean,arr(:,j),findgroups(arr(:,1))); %<----------- error line.
end
c
plot(log(c(:,2)),c(:,1),'b.')
hold on
end
end
.................................................................................................
During each iteration(i), 'c' variable has a different size(i.e. number of elements are changing). Because of which I get following error:
[ Unable to perform assignment because the size of the left side is 3-by-1 and the size of the right side is 4-by-1. ]
Could someone help me in solving this issue? How may I make this array/variable dynamic so that it can store and plot any values in nx3 dimensions. I would really appreciate some help.
0 comentarios
Respuestas (1)
Walter Roberson
el 23 de Oct. de 2023
What reason should we have to expect that there will always be the same number of different groups? splitapply() called that way is going to return one value per group that is found.
Also, findgroups() for numeric data is, in practice, going to create group numbers sorted by the numeric value associated with the group. If in one call the assorted values include (say) 0.1 0.11 0.2 and the next iteration the assorted values include (say) 0.12 0.11 0.2 then in the first iteration group 1 would be for 0.1 and group 2 would be for 0.11 -- but in the second iteration 0.11 would be group 1 instead of group 2. Therefore even if the values are related between iterations, the order might well change, which is likely to cause confusion.
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!