MATLAB Answers

How to place values in vectors from a text file

1 ビュー (過去 30 日間)
Francesco Sortino
Francesco Sortino 2020 年 10 月 9 日
編集済み: madhan ravi 2020 年 10 月 9 日
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

  0 件のコメント

サインインしてコメントする。

回答 (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)

  0 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by