How to store vectors into a matrix that have different sizes?

5 vues (au cours des 30 derniers jours)
Robert  Flores
Robert Flores le 3 Avr 2019
Hello,
I am trying to make a for loop such that I am able to extract median values I did a DIC analysis on. I think the issue is that the sizes of my output verctors are different, therefore it doesn't want to store it in a differently sized matrix, if that makes sense. Below is my code, but I don't know how you will be able to check my code, because you don't have the data from the N_corr software I used for the DIC analysis. Unfortunately,I cannot attach the workspace it is greater than 5MB and I cant zip it because I'll have to close my code and lose my data; so I don't want to do that. I hope my question is weel posed enough that you are able to help me, thanks.
-Robert
Data = handles_ncorr.data_dic;
% The displacements in the Y-direction
V = zeros(297,448);
Vyy = zeros(20863,1);
for i = 1:8
V(:,:,i) = handles_ncorr.data_dic.displacements(i).plot_v_ref_formatted;
avg(i) = mean(mean(V(:,:,i)));
med(i) = median(median(V(:,:,i)));
end
path = "C:\Users\rober\Documents\MATLAB"; filename = 'Medium_Values.csv';
fileid = fopen(path+'\'+filename,'w');
csvwrite(path+'\'+filename,med)
winopen(filename)

Réponses (2)

possibility
possibility le 3 Avr 2019
Hi Robert,
As far as I understand, your remedy is cell arrays. You can collect arbitrary size of vectors into one cell array. In fact, not only different size of vectors, you can even combine different data types. Please check:

Jos (10584)
Jos (10584) le 3 Avr 2019
Next to cell arrays, you can also use struct arrays, which can be more ... euh ... structured than cell arrays ;-)
a(1).data = 1:4
a(2).data = 1:6

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by