How to stop for loop from overwriting

I am trying to solve for Z multiple times due to a change in P. I want to save every result rather than my script cotinuously overwriting the result. How do i do this?
numData = xlsread('Measuring Waves with Pressure Transducers Sheet');
%Pressure From Excel
P = numData(:,13);
Ruskin = numData(:,14);
Burst = numData(:,1);
%Variables from excel calcs
W = 0.392699;
K = 13.8125;
q = 10.13;
d = 9.5;
g = 9.81;
x = 1025;
%Use H=F(Min:Max) for values
for ii = 1:length(P)
syms z
eqn = (P(ii).*10.^4./x)-(q.*10.^4./x)==((W.^2.*cosh(K.*(d+z)))/(sinh(K.*d)))-g.*z;
Sx = solve(eqn,z)
end

 採用された回答

madhan ravi
madhan ravi 2020 年 9 月 4 日

0 投票

Sx = cell(numel(P), 1); % before loop
Sx{ii} = ... inside loop

8 件のコメント

Joshua Foote
Joshua Foote 2020 年 9 月 4 日
The results are being displayed as given:
{0×0 double}
{0×0 double}
{0×0 double}
{0×0 double}
{0×0 double}
{0×0 double}
This does not seem correct?
madhan ravi
madhan ravi 2020 年 9 月 4 日
Paste the code you’re trying.
Joshua Foote
Joshua Foote 2020 年 9 月 4 日
%Pressure From Excel
P = numData(:,13);
Ruskin = numData(:,14);
Burst = numData(:,1);
%Variables from excel calcs
W = 0.392699;
K = 13.8125;
q = 10.13;
d = 9.5;
g = 9.81;
x = 1025;
%Use H=F(Min:Max) for values
Sx=cell(numel(P),1);
for ii = 1:length(P)
syms z
eqn = (P(ii).*10.^4./x)-(q.*10.^4./x)==((W.^2.*cosh(K.*(d+z)))/(sinh(K.*d)))-g.*z;
Sx{ii} = solve(eqn,z)
end
madhan ravi
madhan ravi 2020 年 9 月 4 日
solve() doesn't return any solutions
Joshua Foote
Joshua Foote 2020 年 9 月 4 日
No it does not, but with the layout I had at the beginning of the question I receive solutions. Just need them to not over-write each time
madhan ravi
madhan ravi 2020 年 9 月 4 日
After loop
celldisp(Sx)
Joshua Foote
Joshua Foote 2020 年 9 月 4 日
Ok Thankyou this has worked! How would i be able to write these results to excel?
madhan ravi
madhan ravi 2020 年 9 月 4 日
I answered the original question.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by