I have successfully managed to read a text file containing a large number of values, however, I am unable to use these value in MATLAB. I think this is because in the array they have apostrophe's around the numbers, for example, '0.235659'.
The code I used to read the text file and store the values in an array is:
fid = fopen('Kap.PORO');
tline = fgetl(fid);
tlines=cell(0,1);
while ischar(tline)
%disp(tline)
tlines{end+1,1}=tline;
tline = fgetl(fid);
end
fclose(fid);
I was wondering if anyone knew how to either convert these into an array where I can use the values or a better way of storing values from a TXT file.
Thanks

댓글 수: 1

Stephen23
Stephen23 2015년 4월 23일
편집: Stephen23 2015년 4월 23일
It is likely that textscan (or one of the similar functions) would be much easier to use.
If you simply upload your textfile using the paperclip button above the textbox, then we can try it for ourselves. This is much easier for everyone! You will need to push both the Choose file and Attach file buttons.

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

 채택된 답변

Stephen23
Stephen23 2015년 4월 24일
편집: Stephen23 2015년 4월 24일

0 개 추천

The single quotes indicate that this is a cell-array of strings, where the strings contain some numeric values. Note that this is quite a different thing to a call array of numeric values:
>> {'1.2','3.4','5.6'} % cell array of strings
ans =
'1.2' '3.4' '5.6'
>> {1.2,3.4,5.6} % cell array of numeric values
ans =
[1.2000] [3.4000] [5.6000]
To convert a cell array of strings to a numeric array you can simply use str2double like this:
>> str2double({'1.2','3.4','5.6'})
ans =
1.2000 3.4000 5.6000
But the best solution is still likely to be to import the data using textscan.

추가 답변 (0개)

카테고리

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

제품

질문:

2015년 4월 23일

편집:

2015년 4월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by