Import data from txt file in to a 2D array

34 ビュー (過去 30 日間)
Cosimo Mercuro
Cosimo Mercuro 2021 年 1 月 29 日
コメント済み: Cosimo Mercuro 2021 年 1 月 31 日
Hi.
I've this txt file:
I'd like that all number (32) that are between the square barckets will be the first rows of a 2D array (matrix) 24x32 .
Anything like this:
Any idea?
Thanks in advance

採用された回答

Scott Ronquist
Scott Ronquist 2021 年 1 月 29 日
Hello Cosimo,
I understand you are trying to import the data stored in "acquisizione2-new.txt" into the MATLAB Workspace. This is possible with the Name-Value Pair Arguments available for the readtable function. After importing the data, there is one extra step that is necessary to remove NaN columns in the table output from readtable.
Please try the code given below, hope this helps!
data = readtable("acquisizione2-new.txt",'ReadVariableNames',false,...
'Delimiter',[" ","]","["], 'LineEnding', "]\n",'TrimNonNumeric',true);
% find NaN columns
nanIdx = arrayfun(@(x) all(isnan(data{:,x})), 1:width(data));
% remove NaN columns
data(:,nanIdx) = [];
% convert to numeric array (optional)
dataMatrix = data{:,:};
  3 件のコメント
Cosimo Mercuro
Cosimo Mercuro 2021 年 1 月 31 日
Many thanks.
I'll follow your suggestions.

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

その他の回答 (0 件)

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by