Please help. I need to read this file and isolate column 2.

2 ビュー (過去 30 日間)
Charles Naegele
Charles Naegele 2018 年 5 月 17 日
コメント済み: John BG 2018 年 5 月 18 日
It appears the data is not separated into columns. Any way to do this?
A = importdata('Psmall.txt');
A1 = A(:,2);
  5 件のコメント
the cyclist
the cyclist 2018 年 5 月 17 日
To be clear, when I run your code, I get an Nx2 matrix (of data type "double"). As Star Strider said, it is then easy to separate them into the column vector.
Is that what you get?
Charles Naegele
Charles Naegele 2018 年 5 月 18 日
You were both correct, I had it right in the original code. Sorry for the confusion. Thanks for your responses!

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

採用された回答

John BG
John BG 2018 年 5 月 17 日
Hi Charles Naegele
1.
You are having the same result as if you were using textscan instead of importdata
fid1=fopen('Psmall.txt');
B=textscan(fid1,'%s');
fclose(fid1)
B1=B{1}
B2=cell2mat(B1)
B2 has as single column with all data, as you mention it happens in your data acquisition.
2.
Try
A=importdata('Psmall.txt','\t')
Note that your data file has a TAB as separator, not the default ' ' (space) or comma. Despite MATLAB help for import data reads
The default character is interpreted from the file.
It may be the case an earlier version of MATLAB doesn't really consider TAB as a column separator.
If you upgrade your MATLAB version you will solve this and possibly other compatibility issues to come.
If you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance for time and attention
John BG
  2 件のコメント
Charles Naegele
Charles Naegele 2018 年 5 月 18 日
Turns out I had it correct in the original code, but I thought this answer might be useful to someone else in the future. Thanks!
John BG
John BG 2018 年 5 月 18 日
thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by