Hi!
I was given some data where Y axis is in uV and X axis in seconds. I want to change both units to mV and to hours.
My problem is that the data is "loaded" to my matlab code, for instance:
s1=load('data.txt');
So I don't know how to change the units.

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 6일

1 개 추천

In the following example, I assumed that 1st column in data.txt is x-values and 2nd column is y-values
s1 = load('data.txt');
t = s1(:,1);
uV = s1(:,2);
t_hour = t/3600;
mV = uV/1000;
plot(t_hour, mV)

댓글 수: 8

Laura Ferrer Pascual
Laura Ferrer Pascual 2020년 11월 6일
Thank you, but I must have specified my question.
After loading the data, I have functions defined by this data, for instance:
RE=interp1(s1(:,1), s1(:,2), t, 'nearest');
TE=interp1(s2(:,1), s2(:,2), t, 'nearest')
And then I define another function, for example O=RE-TE
So I don't want to plot(t_hour,mV), I want to plot(O). So is it possible to change the units after defining TE and RE?
interp1() is a piecewise linear transformation, so you can change the units after calculating RE and TE too.
RE=interp1(s1(:,1), s1(:,2), t, 'nearest');
TE=interp1(s2(:,1), s2(:,2), t, 'nearest');
O=RE-TE;
O_mV = O/1000;
plot(t/3600, O_mV)
Laura Ferrer Pascual
Laura Ferrer Pascual 2020년 11월 6일
Sorry I think I'm not explaining very well. s1 has two columns (one for x values and another for y values), so RE and TE are functions that depend on x and y (uV and s), and therfore the function 0 also depends on x and y, is not just y
Ameer Hamza
Ameer Hamza 2020년 11월 6일
From your code, if I understand correctly, RE and TE have units of seconds (y-values) and variable 't' have unit of 'uV'. Are you trying to do this, or the units are opposite?
Laura Ferrer Pascual
Laura Ferrer Pascual 2020년 11월 6일
Is the opposite, RE and TE have units of uV and t of seconds
Ameer Hamza
Ameer Hamza 2020년 11월 6일
But what about units of columns in data.txt. Is first (seconds) and second (uV)?
Laura Ferrer Pascual
Laura Ferrer Pascual 2020년 11월 6일
Yes! First column is s and second column is uV
Ameer Hamza
Ameer Hamza 2020년 11월 6일
In that case, the unit of RE and TE are also uV. Consequently, the unit of O is also uV. The last code in my comment should work.

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

추가 답변 (1개)

KSSV
KSSV 2020년 11월 6일

0 개 추천

To convert seconds to hours multiply t by
t_in_hours = t_in_seconds*1/(60*60) ;
To convert uV to mV, multiply v by
V_in_mV = V_in_uV*1/1000 ;

댓글 수: 1

To make the time conversion a bit more self-explanatory in the code you can use the seconds and hours functions.
>> s = 7200;
>> h = hours(seconds(s))
h =
2
Another example: a million minutes is a little under 2 years.
>> years(minutes(1e6))
ans =
1.90132431040869
There's also a days function you can use for this purpose.

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

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

질문:

2020년 11월 6일

댓글:

2020년 11월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by