Matlab reads file with different order

조회 수: 2 (최근 30일)
chntua chntua
chntua chntua 2020년 8월 31일
댓글: chntua chntua 2020년 9월 1일
Hello ,
Can anyone help me as i put into matlab this txt file and it read it like that :
0.9011 0.5400
0.8480 1.4457
0.6744 1.180
thanks in advance
  댓글 수: 2
per isakson
per isakson 2020년 8월 31일
How exactly did you read the txt-file?
chntua chntua
chntua chntua 2020년 8월 31일
i use fopen to open the txt file and fscanf to print the matrix

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

채택된 답변

per isakson
per isakson 2020년 8월 31일
편집: per isakson 2020년 9월 1일
>> fid = fopen('RQ_par.txt');
>> fs = fscanf( fid, '%f' )
fs =
0.9011
0.848
0.6744
0.54
1.4457
1.18
>> fclose(fid);
This shows how the numbers are stored in a sequence in the file on the disk. Then the reading function "decides" what are rows and what are columns. Matlab is "column major". C is row major.
Two better alternatives to read your file with R2018b are
>> dlmread('RQ_par.txt')
ans =
0.9011 0.848
0.6744 0.54
1.4457 1.18
>> rq = load('RQ_par.txt')
rq =
0.9011 0.848
0.6744 0.54
1.4457 1.18
>>
  댓글 수: 9
per isakson
per isakson 2020년 9월 1일
편집: per isakson 2020년 9월 1일
Read my answer and my comments once more. I cannot explain better.
chntua chntua
chntua chntua 2020년 9월 1일
okay thanks a lot for your time !

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

추가 답변 (1개)

John D'Errico
John D'Errico 2020년 8월 31일
Must I point out the data in that file are arranged as:
data = textread('RQ_par.txt')
data =
0.9011 0.848
0.6744 0.54
1.4457 1.18
MATLAB will read in each line, one at a time. That is how the file is set up.
If you want to change the order to a different order, it is not how you read the file in, but how you perform the re-arrangment.
data = reshape(data',3,2)
data =
0.9011 0.54
0.848 1.4457
0.6744 1.18
  댓글 수: 1
chntua chntua
chntua chntua 2020년 8월 31일
yes but the problem is that matlab does not read it as in text file. can you please check my code ? it is just 4 lines.

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

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by