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.
Image Analyst
Image Analyst 2021 年 4 月 25 日
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
Image Analyst
Image Analyst 2021 年 4 月 26 日
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 ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by