Hello everyone! I need some help regarding creating a dynamic/flexible array/matrix in matlab?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
AAQIB PEERZADA
am 3 Mai 2016
Kommentiert: AAQIB PEERZADA
am 3 Mai 2016
Here is my question. I have matrix which is updating itself at every iteration, and at each iteration i have to extract some information from this matrix and store it in another matrix. The information coming from the first matrix keeps changing with every iteration and hence I have changing data coming in which I need to store in a different matrix. So the size of the other matrix will change at each iteration. MATLAB gives me an error, "subscript assignment dimension mismatch", because the dimension of other matrix changes. here is my code
for h=1:1:length(Lf)-5
d1(:,h)=find(C1(:,:,h));
for a=1:1:length(d1(:,h))
[I(a,h),J(a,h)]=ind2sub(29,d1(a,h));
end
for g=1:1:length(d1(:,h))
Clusters(g,:,h)=[I(g,h) J(g,h)];
end
So here C1 is a matrix i have already created which has the same dimensions every time. But i have to get the indices of the non-zero elements of C1 at each iteration(h), and store those linear indices in d1. And d1 changes size at every iteration(h), because the number of non-zero elements in C1 change with each iteration count. So when i try to execute
d1(:,h)=find(C1(:,:,h));
At the second iteration number (h=2), MATLAB says "subscript assignment dimension mismatch", because the number of non-zero elements at h=2 is different than at h=1, and they are different for all other values of h.
So is there a way I can create this dynamic array/matrix "d1", such that it can accommodate the linear indices of any number of non-zero elements coming from C1 at each iteration, without giving me any error?
0 Kommentare
Akzeptierte Antwort
CS Researcher
am 3 Mai 2016
Use a cell array.
d1{1,h} = find(C1(:,:,h));
3 Kommentare
CS Researcher
am 3 Mai 2016
Bearbeitet: CS Researcher
am 3 Mai 2016
Do this:
[I(a,h),J(a,h)] = ind2sub(29,d1{1,h});
Hope this helps! Also, accept the answer if it worked for you so it can help others too.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!