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

回答(1 个)

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 个评论

Goodevening sir, I tried using this code but an error occurs on "h(xx,:)=w';" part. I cant figure out what is wrong. hmmm.
Post the error message
And if possible post a sample of your data
Error in ==> SolvingRoots at 11 h(:,xx)=w';
this is what matlab always tell me.
Please post the complete error message.
??? 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;
i've done what you told me to do yet it still said the same thing. same error message

此问题已关闭。

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by