Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to place values in vectors from a text file

1 回表示 (過去 30 日間)
Francesco Sortino
Francesco Sortino 2020 年 10 月 9 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi,
I'm very new to Matlab, and have to find in a text some variables to store in separate vectors (a,b,c,d) to then plot and manage these data.
The input text looks like:
timestamp|tag|12 34 56 45|
timestamp|othertag|value|
timestamp|othertag2|value2|
timestamp|othertagN|valueN|
timestamp|tag|12 34 56 48|
..."
My idea is to "look" for the tag I am looking at, grab the data between the || after the specified tag, and then store each coordinate in a n_ish position of the proper coordinate vector.
But I really don't know how to even start in that.
Any help would be much appreciated.
Thanks

回答 (1 件)

madhan ravi
madhan ravi 2020 年 10 月 9 日
編集済み: madhan ravi 2020 年 10 月 9 日
T = readtable('Test.txt', 'ReadVariableNames', 0);
C = cellfun(@(x) sscanf(x, '%d').', T{ismember(T{:, 2}, 'tag'), end},...
'un',0);
Wanted = cell2mat(C)

Community Treasure Hunt

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

Start Hunting!

Translated by