Hello,
I am trying to find the column in which the top row of my matric c reahes 0.7 and its corresponding position in matrix h. I don't need all the values after it reaches 0.7, just the column it first reaches it.
Please could someone help me.
Thank you.

 채택된 답변

Image Analyst
Image Analyst 2021년 4월 25일

1 개 추천

Try this:
columnIndex = find(c(1, :) >= 0.7, 1, 'first') % For matrix c
columnIndex = find(h(1, :) >= 0.7, 1, 'first') % For matrix h

댓글 수: 4

Sam Robinson
Sam Robinson 2021년 4월 25일
This has worked to get my value in the c matrix, thank you.
But for the h matrix how can I write my code to dispaly the value in the column number from my matrix c?
For example, if its column 123 in matrix c (this value depends on my inputs) how can I get it to display the value for that position in h.
columnIndex = find(c(1, :) >= 0.7, 1, 'first') % For matrix c
hValue = h(1, columnIndex) % Get h value at row 1, and in the same column as we found for c.
Sam Robinson
Sam Robinson 2021년 4월 26일
How do I make this if 0.7 doesnt show in the top row of my c matrix? how do I get it to search each row at a time and tell me the row and column that it first appears in?
Appreciate your help
Use a for loop
[rows, columns] = size(c)
columnIndexes = zeros(rows, 1); % Preallocate a column for every row in the matrix.
hValues = zeros(rows, 1); % Preallocate a column for every row in the matrix.
for row = 1 : rows
location = find(c(1, :) >= 0.7, 1, 'first') % For matrix c
if ~isempty(location)
columnIndex(row) = location; % For matrix c
hValue(row) = h(row, location) % Get h value at row 1, and in the same column as we found for c.
end
end
% If any row did not have any value over 0.7,
% then columnIndex for that row will be zero.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2021년 4월 25일

댓글:

2021년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by