Store values from a for loop into a matrix
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hello all, if anyone could possibly help me I would greatly appreciate it. I am attempting to store values calculated in a for loop in a matrix. I have already tried to preallocate arrays and create an empty matrix but just cant seem to get it to work.
The matrix would be [65x3] because there are 3 conditions and 65 participants. The for loop calculates one condition from one participant at a time.
for RARs = zeros(65, 3)
i = 1:65;
RARatio = AUC/RA;
disp(RARatio)
% RAR Matrix
RARmat(RARs, :) = RARatio;
end
Thank you in advance!
採用された回答
madhan ravi
2019 年 9 月 22 日
RARmat = zeros(65, 3)
for ii = 1:65
RARatio = AUC/RA;
disp(RARatio)
% RAR Matrix
RARmat(ii, :) = RARatio;
end
11 件のコメント
Thank you so much!! That definitely works!
Follow up question: Is there any way to qualify that every third iteration of the for loop starts a new row?
madhan ravi
2019 年 9 月 22 日
ii = 3:3:65
Jo E.
2019 年 9 月 22 日
Not quite working. But thank you anyway!
madhan ravi
2019 年 9 月 22 日
What’s not working ? It’s always a good idea to illustrate of what you’re describing, so that it’s easy for people to answer.
madhan ravi
2019 年 9 月 22 日
Jo E. comments:
I attached a picture of what is coming up when I added this code
ii = 3:3:65
What I am actually looking to do is that each participant has 1 row of 3 columns meaning that 3 itirations of the loop will fill the first row across 3 colums and the 4th itiration will start a new row.
Thank you for the help.
madhan ravi
2019 年 9 月 22 日
編集済み: madhan ravi
2019 年 9 月 22 日
Please don't keep adding answers just to make a comment. Use Comment on this Answer instead.
Perhaps you just want:
ii = 1:3:65
Even if the above doesn't do what you want , you need to show how your expected result should look like with an explicit example.
Jo E.
2019 年 9 月 22 日
I have attached a photo of what I am looking to be populated in the matrix. After 6 itirations of the loop I will need 2 rows of 3 conditions. I hope that clarifies what I am asking.
madhan ravi
2019 年 9 月 22 日
編集済み: madhan ravi
2019 年 9 月 22 日
You keep on changing your question in each comment. Your original question was how to store values in each iteration. Attach your data as .mat file.
Yes and you answered it wonderfully. I asked the follow up question of how to store values of each itiration in a new row after the 3rd iteration. Thank you for your help thus far.
madhan ravi
2019 年 9 月 22 日
You would be better off starting a new question (also link this thread to that question), so that you get a help soon.
Jo E.
2019 年 9 月 22 日
Will do. Thank you for your help.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
