How can I load out the data to array from several specific column number?

조회 수: 4 (최근 30일)
Evelyn Chen
Evelyn Chen 2024년 8월 20일
댓글: Shashi Kiran 2024년 8월 20일
I want to load out some specific data from my txt. file to array and I know the column number of data which I want to load out.
EX. column: 20, 86, 150, 235, 375, 568 ...
It's two rows of data file.
I have no idea on how to do.
Thanks for the help!

답변 (1개)

Shashi Kiran
Shashi Kiran 2024년 8월 20일
편집: Shashi Kiran 2024년 8월 20일
You can extract specific columns from the text file using the following approach:
data = load('your_file.txt');
% Specify the columns you want to extract
columns = [20, 86, 150, 235, 375, 568];
% Extract the specified columns from the data
selectedData = data(:, columns);
Just replace 'your_file.txt' with the actual name of your file.
Hope this helps!
  댓글 수: 2
Evelyn Chen
Evelyn Chen 2024년 8월 20일
Thanks for your help!
On the other hand, I use the readmatrix to load the txt file.
And the window shows error about "Index in position 2 exceeds array bounds. Index must not exceed 7."
Is there anything that I can do to correct it?
Shashi Kiran
Shashi Kiran 2024년 8월 20일
The Error suggests that the readmatrix is reading only 7 columns from the text file.
If you could share the corresponding text file I would help further.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Identification에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by