Trying to create two arrays called z and y

2 ビュー (過去 30 日間)
Kelton McKee
Kelton McKee 2020 年 1 月 15 日
コメント済み: Walter Roberson 2020 年 2 月 9 日
% create variable x with array of all necessary values
x=linspace(0.1,13,50);
for i=x
% create equation to determine y
y=(sqrt(2.*i)*4*i.^3)/(4.*i(1)+7.^(i/10));
%create equation to determine z
z=log10(2.*i+5)+(4.*i+exp(i))/(2./3+4.*i.^2);
end
For the code above im trying to use values from my x array to create two arrays, y and z, im pretty new to matlab and im struggling, thanks.
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 2 月 9 日
Copy of the question in case the user edits it away like they did other questions:
% create variable x with array of all necessary values
x=linspace(0.1,13,50);
for i=x
% create equation to determine y
y=(sqrt(2.*i)*4*i.^3)/(4.*i(1)+7.^(i/10));
%create equation to determine z
z=log10(2.*i+5)+(4.*i+exp(i))/(2./3+4.*i.^2);
end
For the code above im trying to use values from my x array to create two arrays, y and z, im pretty new to matlab and im struggling, thanks.

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

採用された回答

Cameron B
Cameron B 2020 年 1 月 15 日
編集済み: Cameron B 2020 年 1 月 15 日
First I would rename the variable i as ii so it’s not confused with the more general use of i = sqrt(-1). To save the variable, you need to index them. You can either have them as one row full of data or one column. Because this looks like homework I don’t want to write it all out for you. But while you’re going through the for loop, you’ll need to save the variable to a new position each time so it doesn’t overwrite. I’ll give you an example.
indx = 1; %starting value for array end
pp = 0:0.2:5;
for xx = pp
y(indx,1)= xx^2; %y variable is saved in a different column position each time through the loop
indx = indx + 1; %increment your value by one to save it to a new spot
end
disp(y) %displays your y variable in the command windiw
plot(pp,y) %plots your pp vs your y
  1 件のコメント
Kelton McKee
Kelton McKee 2020 年 1 月 15 日
Thank you! i was able to apply your method and it worked perfectly

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by