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.

 Réponse acceptée

Image Analyst
Image Analyst le 25 Avr 2021

1 vote

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 commentaires

Sam Robinson
Sam Robinson le 25 Avr 2021
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 le 26 Avr 2021
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by