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?
ii = 3:3:65
Jo E.
2019년 9월 22일
Not quite working. But thank you anyway!
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.
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.
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
