Saving data from a loop

Goodday everyone,
I am a newbie in using matlab software and I find it difficult on storing an answer from a loop in a designated variable. I was planning to store the roots of an equation by which the constant variables of the 6th degree polynomial was imported from excel file. I was planning to store the values in columns of the "h" variable. Hope you can help me regarding this matter. The matlab code that i created is shown below.
Thank you very much!
data=xlsread('Soil Characterization.xlsx',5,'C17:K23');
L=length(data(1,:));
x=1;
for xx=1:L+1;
if (xx<L+1);
a = data (1, xx);
b = data (2, xx);
c = data (3, xx);
d = data (4, xx);
e = data (5, xx);
f = data (6, xx);
g = data (7, xx)-10;
y=[a b c d e f g];
w=roots(y);
end
h(x,:)=w;
x=x+1;
end

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 8 Juil 2015
Modifié(e) : Azzi Abdelmalek le 8 Juil 2015

0 votes

data=xlsread('Soil Characterization.xlsx',5,'C17:K23');
L=length(data(1,:));
h=zeros(L,6)
for xx=1:L;
y=[data(1:6,xx)' data (7, xx)-10 ];
w=roots(y);
h(xx,:)=w';
end

8 commentaires

Ezequiel Male
Ezequiel Male le 8 Juil 2015
Goodevening sir, I tried using this code but an error occurs on "h(xx,:)=w';" part. I cant figure out what is wrong. hmmm.
Azzi Abdelmalek
Azzi Abdelmalek le 8 Juil 2015
Post the error message
Azzi Abdelmalek
Azzi Abdelmalek le 8 Juil 2015
And if possible post a sample of your data
Ezequiel Male
Ezequiel Male le 8 Juil 2015
Error in ==> SolvingRoots at 11 h(:,xx)=w';
this is what matlab always tell me.
Jan
Jan le 8 Juil 2015
Please post the complete error message.
Ezequiel Male
Ezequiel Male le 9 Juil 2015
Modifié(e) : Ezequiel Male le 9 Juil 2015
??? Subscripted assignment dimension mismatch.
Error in ==> SolvingRoots at 11 h(:,xx)=w;
its all what matlab says. i dont know why when i look in the "h" array, all the values are zero
you wrote
h(:,xx)=w;
In my code it's
h(xx,:)=w;
Ezequiel Male
Ezequiel Male le 14 Juil 2015
i've done what you told me to do yet it still said the same thing. same error message

Cette question est clôturée.

Clôturé :

le 20 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by