'dlmread' function reads the variables as a*10^-3.

Guys i was working on my homework and first i tried the dlmread function like a=dlmread('Yeni Metin Belgesi.txt') but it gave file could not be found then i used a=dlmread('C:\Users\omer\Desktop\Yeni Metin Belgesi.txt') it found the file but now it reads the variables like if variable is 0.1 it reads 0.0001. What is the problem? How can i fix?

11 Comments

Could it be that 0.1 looks like 0.0001 when it is displayed in the Command Window, due to other elements being much larger in magnitude?
Note the 1.0e+03 * here:
disp([0.1 1000])
1.0e+03 * 0.0001 1.0000
To know for sure, can you attach the file to your question using the paperclip icon?
I added both matlab and text file could you check it?
Looks like what I said (and what @Star Strider said):
a=dlmread('values.txt')
a = 15×6
1.0e+03 * 0.0010 0.0070 0.0000 0.1292 0.0293 2.3845 0.0015 0.0130 0.0000 0.0880 0.0547 2.3928 0.0020 0.0175 0.0000 0.0670 0.0734 2.3989 0.0025 0.0211 0.0000 0.0542 0.0884 2.4038 0.0030 0.0241 0.0000 0.0457 0.1010 2.4079 0.0040 0.0290 0.0000 0.0348 0.1214 2.4145 0.0050 0.0329 0.0000 0.0282 0.1378 2.4198 0.0060 0.0362 0.0000 0.0237 0.1515 2.4242 0.0070 0.0390 0.0000 0.0205 0.1633 2.4281 0.0080 0.0415 0.0000 0.0181 0.1738 2.4314
The first value in the text file is 1. But other values in the text file go up to about 2400 or so.
When MATLAB displays a matrix with values that range over multiple orders of magnitude like that, it tries to pick a power of 10 common to all elements in order to try to display everything in a compact manner. For instance, if all the values were around 1e-9 it might look like this:
disp([1 2 3]*1e-9)
1.0e-08 * 0.1000 0.2000 0.3000
where the common factor is 1e-8, rather than putting 8 zeros behind the decimal point for each number, as in:
disp(['0.000000001 0.000000002 0.000000003']);
0.000000001 0.000000002 0.000000003
The first way is more compact and you can easily read the magnitude of each value instead of having to count the zeros.
So that's what's going on with the numbers from your file. Look at what happens when you just show the first 5 columns (leaving off the last column, which has all the very high values):
a(:,1:5)
ans = 15×5
1.0000 6.9705 0.0010 129.1900 29.3020 1.5000 13.0205 0.0010 87.9640 54.6860 2.0000 17.4957 0.0010 66.9900 73.4310 2.5000 21.0777 0.0010 54.2420 88.4220 3.0000 24.0796 0.0010 45.6540 100.9800 4.0000 28.9607 0.0010 34.7910 121.3900 5.0000 32.8743 0.0010 28.1850 137.7500 6.0000 36.1587 0.0010 23.7330 151.4700 7.0000 38.9992 0.0010 20.5240 163.3400 8.0000 41.5082 0.0010 18.0990 173.8300
Now there is no common factor, i.e., everything is shown as it really is in the file (except rounded to four decimal places), because every value is not too many orders of magnitude away from 1.
Note that in every case, the file is being read properly, and the confusion is due to how the numbers are displayed in the Command Window.
As i understood it reads correctly right if we use it without displaying for the next commands?
dlmread seems to be working correctly, yes.
Okey then i want to find value of vg for example when T=10 with usinf interp1 function. Can you again help me because i am in trouble with this homework? :')
These are the name of the columns:
P=Properties(:,1);
T=Properties(:,2);
vf=Properties(:,3);
vg=Properties(:,4);
uf=Properties(:,5);
ug=Properties(:,6);
And also if you have knowledge about thermodynamics i can totaly ask questions about homework. :D
a = dlmread('values.txt');
% interpolate:
% given T=a(:,2) and vg=a(:,4), find vg when T=10:
interp1(a(:,2),a(:,4),10)
ans = 108.5463
Thank you! You helped me so much.
You're welcome!
So _ how can i use P in while loop? For example P will increase until the uf equals a some value.
ii = 1;
P = Properties(ii,1);
uf = Properties(ii,5);
uf_max_value = 1000;
while uf < uf_max_value
% do stuff here, with P and uf, etc.
ii = ii+1;
P = Properties(ii,1);
uf = Properties(ii,5);
end

Sign in to comment.

Answers (1)

Most likely, it is assigning a common multiple to the matrix being read.
format long
v = logspace(-3, 3, 9)'
v = 9×1
1.0e+03 * 0.000001000000000 0.000005623413252 0.000031622776602 0.000177827941004 0.001000000000000 0.005623413251903 0.031622776601684 0.177827941003892 1.000000000000000
Check to see if a common multiplication factor (here 1.0e+03) exists in the display.
.

5 Comments

Sorry i could not understand, yes there is '1.0e+03 *' but i do know the reason of it. But i did not find how to solve this. ALso I added both matlab and text file, if you want to check it.
You don't need to solve anything. This is just how the numbers are displayed.
format long
v = logspace(-3, 3, 9)'
v = 9×1
1.0e+03 * 0.000001000000000 0.000005623413252 0.000031622776602 0.000177827941004 0.001000000000000 0.005623413251903 0.031622776601684 0.177827941003892 1.000000000000000
You have a vector with numbers of very different magnitude. So MATLAB decided to display the numbers with a common factor of 1e3 factored out.
v(1)
ans =
1.000000000000000e-03
v(end)
ans =
1000
Your numbers are fine. There is nothing to "solve".
One option may be to use the format function, specifically either:
format shortE
format longE
to produce:
format shortE
v = logspace(-3, 3, 9)'
v = 9×1
1.0e+00 * 1.0000e-03 5.6234e-03 3.1623e-02 1.7783e-01 1.0000e+00 5.6234e+00 3.1623e+01 1.7783e+02 1.0000e+03
That removes the ambiguities.
.
John D'Errico when i interp1(a(:,1),a(:,6),10) the result is 2.4372e+03 so you say there is no way to remove it. right?
Star Strider thank you but i have to use these functions, and i almost done with my problem.

Sign in to comment.

Tags

Asked:

on 26 Mar 2022

Commented:

on 28 Mar 2022

Community Treasure Hunt

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

Start Hunting!