フィルターのクリア

Add values to a matrix from a loop

54 ビュー (過去 30 日間)
Thang  Le
Thang Le 2014 年 3 月 7 日
コメント済み: Image Analyst 2021 年 9 月 30 日
Hi,
I have the following lines in my script:
for j=0:15;
percentage_change = (x((8+j),k)-baseline1)/baseline1*100;
end
The above gives me 16 different values. Could anyone please tell me how I would go about putting all these 16 values in an empty 16x1 matrix called P? Thank you so much for your help.

回答 (3 件)

Poongavanam Palani
Poongavanam Palani 2019 年 10 月 9 日
This should help!
P = [];
for j = 1:15
percentage_change = (x((8+j),k)-baseline1/baseline1*100;
P = [P, percentage_change,];
end

Image Analyst
Image Analyst 2014 年 3 月 7 日
P = percentage_change;
Of course after you do that P is no longer empty.
  18 件のコメント
Image Analyst
Image Analyst 2014 年 3 月 8 日
Since I can't run your code. I really recommend you take the same actions I would take to solve your issues. And that is to carry out the actions you will learn in this video: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
Thang  Le
Thang Le 2014 年 3 月 8 日
I will. Thank you for all your help and patience, especially on a Friday and Saturday. Have a great weekend!

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


Jacques
Jacques 2014 年 3 月 8 日
P = zeros(16,1);
for j=0:15;
percentage_change = (x((8+j),k)-baseline1)/baseline1*100;
P(j+1) = percentage_change;
end
Sorry for not indenting code, I don't know how to do that...
  3 件のコメント
Nathanael Ferster
Nathanael Ferster 2021 年 9 月 30 日
This helped me too, thanks.
Image Analyst
Image Analyst 2021 年 9 月 30 日
@Nathanael Ferster, glad it helped. Maybe it's a little known trick. If more people would type control-a then control-i in MATLAB before pasting in here, then it would sure make the code easier to follow. Of course after they paste it in, they still need to highlight it and click the Code icon to format it as code and enable the "copy" button so that people can copy the entire code with one click.

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by