How I can read notbad file Line by Line?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
I saved matrices in text file line by line and now I want to read these matrices in same way that I saved?
2 Comments
Geoff Hayes
on 28 Mar 2015
Ameligege - what is the code that you used to save the data to file?
Ameligege
on 28 Mar 2015
Answers (1)
Image Analyst
on 28 Mar 2015
0 votes
Try dlmread(), csvread(), importdata(), fgetl(), textscan(), or readtable(). Lots of ways to do it. Examples are in the help. Just pick one or two and give it a try. In the event someone did want to do it for you, you didn't attach your file, so they can't.
19 Comments
Jan
on 28 Mar 2015
And fscanf.
Image Analyst
on 28 Mar 2015
So you used dlmwrite() to write it out
dlmwrite('Features.txt',reshapemat,'-append', 'newline', 'pc');
but dlmread() is not working? What is your code for dlmread()?
Image Analyst
on 28 Mar 2015
Well, what can I say if you're not willing to attach your file? Just keep working on it, or call the Mathworks on Monday for help. It looks like somewhere you're dividing the array by 100. Are you sure it's not just being displayed in scientific notation?
Ameligege
on 28 Mar 2015
Image Analyst
on 28 Mar 2015
Why does it need to be private? It's just numbers. If there are secret words in some column headers, just change them, and then upload it here.
Ameligege
on 28 Mar 2015
Image Analyst
on 28 Mar 2015
OK, so the first number in the file is 377. Was that the value in MATLAB before you created the file? And what number do you get after calling dlmread()? 377 or 0.377?
Image Analyst
on 28 Mar 2015
I can't reproduce:
m = dlmread('features.txt');
m(1, 2) % Print second number on first row to command line.
In the command window, it shows:
ans =
377.46
It works just fine for me. There's something you're not showing or telling me, like you're using im2double() or dividing by 100 or something.
Image Analyst
on 29 Mar 2015
Right before step 7 (dlmwrite), do this:
save('myarray.mat', 'reshapemat');
dlmwrite('Features.txt',reshapemat,'-append', 'newline', 'pc');
Then attach myarray.mat back here so we can look at it.
Ameligege
on 29 Mar 2015
Image Analyst
on 29 Mar 2015
This has totally different numbers than your first example (311 is not the first number anymore) so that means you're also going to have to attach the features.txt file that has the same numbers. Please hurry as I'm planning on leaving for some errands soon.
Ameligege
on 29 Mar 2015
Ameligege
on 29 Mar 2015
Ameligege
on 29 Mar 2015
Image Analyst
on 29 Mar 2015
Edited: Image Analyst
on 29 Mar 2015
Here is the code I used:
s=load('myarray.mat')
m = s.reshapemat;
Then examine m with the variable editor. And you attached the same features.txt as before. It totally does not match your reshapemat in the slightest.
Ameligege
on 29 Mar 2015
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!