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.

 Respuesta aceptada

Image Analyst
Image Analyst el 25 de Abr. de 2021

1 voto

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 comentarios

Sam Robinson
Sam Robinson el 25 de Abr. de 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.
Image Analyst
Image Analyst el 25 de Abr. de 2021
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 el 26 de Abr. de 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
Image Analyst
Image Analyst el 26 de Abr. de 2021
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 25 de Abr. de 2021

Comentada:

el 26 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by