How I can read notbad file Line by Line?

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

Ameligege - what is the code that you used to save the data to file?
dlmwrite('Features.txt',reshapemat,'-append', 'newline', 'pc');

Answers (1)

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

And fscanf.
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()?
Ameligege
Ameligege on 28 Mar 2015
Edited: Ameligege on 28 Mar 2015
I used dlmread() as follwing
dlmread('Features.txt') but the result is not identical to the text file for example In the notebad file here is one of the values 407.66 but the output is 0.4077 what is the reason?
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?
How can I send it in private way??????
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.
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?
Ameligege
Ameligege on 28 Mar 2015
Edited: Ameligege on 28 Mar 2015
I extract these values from image,so I can not check the value
when I called dlmread() this what I get 0.3775
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.
Ameligege
Ameligege on 29 Mar 2015
Edited: Ameligege on 29 Mar 2015
Here are all my steps
1-Read Images
2-Apply Filter function after convert the image using im2double()
3-convert it to black and white
4-Apply DWT
5-Apply kraskuallwallis
6-reshape the result to save it in notbad file row by row
7-write the reult to notbad file
That all what I did before I saved the result in notbad file I can send the code but in private.
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.
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.
how i can display the content of myarray
311 is already the first element in the text file
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.
Look :( I had to use this function reshapemat=reshape(features, 1, []);
to save the result matrix in one line.
because I want to save each matrix in one line like the notbad that I sent
If you have another way to do the same thing ,please tell me?
Thank you for the sincere help ,I appreciate you for your time and your effort

This question is closed.

Asked:

on 28 Mar 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!