Convert Cell Array To Matrix
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I am trying to convert the cell array to matrix. However, the code below gives error as "Index exceeds matrix dimensions." How can i solve this problem?
clear all
[name]=textread('assign3_520.txt','%s');
for i=1:3
d{i}=textread(name{i},'%f','headerlines',4);
d{i}=d{i}*9.81;
d{i}=detrend(d{i},'constant');
d{i}=detrend(d{i});
dv{i}=cumtrapz(d{i})*0.01;
dd{i}=cumtrapz(dv{i})*0.01;
d(i)=[];
d(i)=cell2mat(d{i});
end
0 commentaires
Réponses (2)
Razvan
le 1 Nov 2011
I would convert the cell array d to a matrix after the for loop, e.g. v = cell2mat(d); Also if you use d(i)=[] in the loop that erases some element that you just read...
0 commentaires
Walter Roberson
le 1 Nov 2011
d(i) = [];
means that d(i) should be deleted. When i=1 this moves d(2) down to d(1) and d(3) down to d(2), with d(3) no longer existing. When i=2 what is now in d(2) (that started as being in d(3)) would be deleted, leaving just d(1) (that started as being in d(2)) and with d(2) and d(3) no longer existing. Then in the next line after that, you try to reference d{2} but d(2) does not exist and hence d{2} does not either.
I cannot advise you as to what you should do with your code as your code is too obscure for me. I don't know why you do not use appropriate temporary variables within the loop and then assign the final d{i} at the end of the loop.
2 commentaires
Walter Roberson
le 1 Nov 2011
You probably should not do that at all. Please see
http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
Voir également
Catégories
En savoir plus sur Logical 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!