This question is closed. Reopen it to edit or answer.

How to place values in vectors from a text file

1 view (last 30 days)
Francesco Sortino
Francesco Sortino on 9 Oct 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
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|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.

Answers (1)

madhan ravi
madhan ravi on 9 Oct 2020
Edited: madhan ravi on 9 Oct 2020
T = readtable('Test.txt', 'ReadVariableNames', 0);
C = cellfun(@(x) sscanf(x, '%d').', T{ismember(T{:, 2}, 'tag'), end},...
Wanted = cell2mat(C)

Community Treasure Hunt

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

Start Hunting!

Translated by