'dlmread' function reads the variables as a*10^-3.
Show older comments
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])
To know for sure, can you attach the file to your question using the paperclip icon?
Ömer Fatih Özdemir
on 26 Mar 2022
a=dlmread('values.txt')
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)
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']);
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)
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.
Ömer Fatih Özdemir
on 26 Mar 2022
Voss
on 26 Mar 2022
dlmread seems to be working correctly, yes.
Ömer Fatih Özdemir
on 26 Mar 2022
a = dlmread('values.txt');
% interpolate:
% given T=a(:,2) and vg=a(:,4), find vg when T=10:
interp1(a(:,2),a(:,4),10)
Ömer Fatih Özdemir
on 26 Mar 2022
Voss
on 26 Mar 2022
You're welcome!
Ömer Fatih Özdemir
on 28 Mar 2022
Edited: Ömer Fatih Özdemir
on 28 Mar 2022
Voss
on 28 Mar 2022
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
Answers (1)
Most likely, it is assigning a common multiple to the matrix being read.
format long
v = logspace(-3, 3, 9)'
Check to see if a common multiplication factor (here 1.0e+03) exists in the display.
.
5 Comments
Ömer Fatih Özdemir
on 26 Mar 2022
Edited: Ömer Fatih Özdemir
on 26 Mar 2022
You don't need to solve anything. This is just how the numbers are displayed.
format long
v = logspace(-3, 3, 9)'
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)
v(end)
Your numbers are fine. There is nothing to "solve".
format shortE
format longE
to produce:
format shortE
v = logspace(-3, 3, 9)'
That removes the ambiguities.
.
Ömer Fatih Özdemir
on 26 Mar 2022
Ömer Fatih Özdemir
on 26 Mar 2022
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!