Info

此问题已关闭。 请重新打开它进行编辑或回答。

How to place values in vectors from a text file

2 次查看(过去 30 天)
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