Hi..
I am trying to read a specific colum from dat file however, the output is 1*2 cell array..
I would like the output to be [2;4;5;7;9].. I attached the file and the code as well
clearvars;
clc;
close all;
fid = fopen('trial_1.dat')
data = textscan(fid, '%d %d[^\n]')
fid = fclose(fid);
% I would like data=[2;4;5;7;9]
Any help please ...
Thanks,

댓글 수: 7

Mathieu NOE
Mathieu NOE 2021년 7월 6일
hi
could also share the dat file as well ?
tx
sci hub
sci hub 2021년 7월 6일
I have been trying but not possible.. I do not understand why ?
Mathieu NOE
Mathieu NOE 2021년 7월 6일
maybe that extension is not supported by this forum, change it to csv or txt and retry
sci hub
sci hub 2021년 7월 6일
just attached.... with different extension..
Mathieu NOE
Mathieu NOE 2021년 7월 6일
seems a friend has already answered your question below ... you can accept it for sure
Stephen23
Stephen23 2021년 7월 6일
편집: Stephen23 2021년 7월 6일
Simpler:
T = readtable('trial_1.dat.txt')
T = 5×2 table
sig olx ___ ___ 1 2 2 4 3 5 4 7 5 9
T.olx
ans = 5×1
2 4 5 7 9
sci hub
sci hub 2021년 7월 9일
Thanks.. it's also working

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

 채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 7월 6일

0 개 추천

No need to use textscan. Just use readmatrix:
f = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/676208/trial_1.dat.txt';
M = readmatrix(f)
M = 5×2
1 2 2 4 3 5 4 7 5 9
M(:,2)
ans = 5×1
2 4 5 7 9

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import and Export에 대해 자세히 알아보기

질문:

2021년 7월 6일

댓글:

2021년 7월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by