Hi guys,
I'm trying to workout a percentage for button errors using a loop. I have managed to do this but I can't figure out how to stop overwriting my previous loop. Its the last line i'm having trouble with and I'm not sure whether putting this into a matrix is the correct way of saving the percentage.
for i = 1:numel(fields);
for j = 1:numel(fieldsone);
count_rows = height (ButtonError.(fieldsone{j}));
rows = height (my_structure.(fields{i}));
percent = count_rows/rows*100;
percentageError {i}= [percent];
end
end
TIA

 채택된 답변

Cris LaPierre
Cris LaPierre 2020년 12월 1일
편집: Cris LaPierre 2020년 12월 1일

0 개 추천

You have two for loops with loop counters i and j. You last line is using the outer counter, i. If you want to keep every value, you will need to use both indices. Try something like this
percentageError(i,j)= [percent];

댓글 수: 2

Sophia Vaccarella
Sophia Vaccarella 2020년 12월 1일
Thank you! This works although I now have a matrix in which each row/column is repeated 8 times, I'm not sure if there is another way to avoid this but I think i'll just get rid of this after :)
Cris LaPierre
Cris LaPierre 2020년 12월 1일
If you are getting repeated values, that tells me you can probably get rid of one of your loops.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 12월 1일

0 개 추천

Why not do
percentageError(i, j) = percent;

댓글 수: 1

Sophia Vaccarella
Sophia Vaccarella 2020년 12월 1일
This worked the same as the above answer, thank you!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 12월 1일

댓글:

2020년 12월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by