Filter löschen
Filter löschen

find and print values ​​from matrix

4 Ansichten (letzte 30 Tage)
Esra Demirbilek
Esra Demirbilek am 28 Mär. 2022
Kommentiert: Voss am 29 Mär. 2022
Hello everyone ,
works: 1 2 3 4 5 6
A1 3 1 2 2 3 1
A2 2 3 3 1 2 3
Can I find the value 2 in each row in the matrix given above and print the job number in another matrix?
Example: I found 2 values in row A1 in the given matrix. These are the 3rd and 4th jobs. I need to print these jobs in a matrix like below.
Works: 2
3
4

Akzeptierte Antwort

Voss
Voss am 28 Mär. 2022
% given matrix with three rows:
M = [ ...
1 2 3 4 5 6; ...
3 1 2 2 3 1; ...
2 3 3 1 2 3];
% value to look for in the second row of M:
val = 2;
% find the indices where val is in the second row of M:
idx = find(M(2,:) == val);
% output is val followed by those indices, all together in a column vector:
output = [val; idx(:)]
output = 3×1
2 3 4
  4 Kommentare
Esra Demirbilek
Esra Demirbilek am 29 Mär. 2022
thank you
Voss
Voss am 29 Mär. 2022
You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by