How can I extract values of last three columns in a matrix when second column value is 2?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Preyanka Dey
am 21 Feb. 2020
Kommentiert: Preyanka Dey
am 21 Feb. 2020
Hi,
Can anybody please help me in extracting values of last three columns from the attached icon.txt file in a matrix? It should store the values when second column value is 2. The output should be like the following:
38 3 2 % first line
3 40 2
10 39 1
66 4 3
36 73 37
3 74 40
75 3 38
------
-------
71 3 133 % last line
0 Kommentare
Akzeptierte Antwort
Bhaskar R
am 21 Feb. 2020
Bearbeitet: Bhaskar R
am 21 Feb. 2020
data = readmatrix('icon.txt');
req_data = data(data(:, 2)== 2, end-2:end);
If you are using MATLAB older version than R2019a
f = fopen('icon.txt');
data = cell2mat(textscan(f, repmat('%d', 1, 8), 'CollectOutput',true));
fclose(f);
req_data = data(data(:, 2)== 2, end-2:end);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Holidays / Seasons finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!