How can I query data?
7 ビュー (過去 30 日間)
古いコメントを表示
Hi I don't know to how to explain my problem but I try my best. I need help. I have an excel sheet which contains temperature data with time. 1st column is for time and then 2nd,3rd,4th and 5th column contains temperature data. In temperature column temperature is increasing with time then reached a high temperature after that the temperature is falling. for an example, the temperature is raising from 25 degree to 1000 degree then cooling down from 1000 degree to 25 degree. I have recorded the time every 3 or 2 sec. I need to find the time for two region raising and cooling. what is the time when the temperature is greater than equals to 200, 300,400,500,600. So, for every temperature I have two times: one for raising and one for cooling. Now I am doing this in excel by using data sorting and then find it manually searching in the column.
Could anybody help me how can i do it mathlab. by the by I have almost zero knowledge in matlab.
Thanks in advance.
0 件のコメント
採用された回答
Sven
2012 年 8 月 31 日
Hi Tan, let's take this one step at a time.
STEP 1: Load your data from excel and into MATLAB
allData = xlsread('c:/yourfile.xls')
STEP 2: Visualise your data. From your description, I think you've got a time vector and a column array of temperatures:
timeVec = allData(:,1);
tempVecs = allData(:,2:end);
figure, plot(timeVec, tempVecs)
STEP 3: Find the peak time of all temperatures. MATLAB is great at this kind of thing - you can find the index of the maximum of all your different temperature vectors, all in one command:
[maxTemps, maxIndices] = max(tempVecs,1);
So at what time does each temperature peak?
timeVecs(maxIndices)
STEP 4: Find the times that temperature increases. Let's just take one of your temperatures (ie, the first column) and one of your temperature levels (200deg).
tempNo = 1;
tempThresh = 200;
firstIndex = find(tempVecs(:,tempNo) > tempThresh, 1, 'first');
lastIndex = find(tempVecs(:,tempNo) < tempThresh, 1, 'last');
So, when did the first temperature vector first get past 200?
timeVec(firstIndex)
How long did it take to get down again?
timeVec(lastIndex) - timeVec(firstIndex)
I hope this has helped you get started.
5 件のコメント
Sven
2012 年 8 月 31 日
編集済み: Sven
2012 年 8 月 31 日
About the max() and min() calls. Yes, I made an error that always trips me up. I should have written:
max(tempVecs,[],1)
Which (as long as you have more than one time per temperature, which you do) is the same as:
max(tempVecs)
You can read the explanation of why by typing:
help max
Sven
2012 年 8 月 31 日
About getting the results that you calculate out of MATLAB and into a file, again, should take things 1 step at a time.
1. Get the data you eventually want to save into a MATLAB variable
2. Save the variables to some file
I think that [2] is a different question that you should perhaps ask separately when you get to that stage (you're not there yet). It all depends on what data you have and how you want to use it. You can brush up by typing "doc save" or "doc dlmwrite".
[1] is the real issue. You should definitely check out the "Getting Started" section of the help. It actually is quite helpful. http://www.mathworks.com/help/techdoc/learn_matlab/f2-644.html
If you can understand what the following code does, then you can do step [1] pretty easily:
myData = rand(10,3)
myMaxIndices = zeros(1,3);
for i = 1:3
[maxVal, maxInd] = max(myData(:,i),[],1);
myMaxIndices(i) = maxInd;
end
My suggestion would be to play around a little longer and go through some of the examples in the MATLAB docs. It seems like you can describe what you're trying to do quite clearly, so that's a big benefit. When you hit a new problem that has you stumped, make another question here and you'll get plenty of help.
If this answer has helped you out, go ahead and hit "Accept Answer" :)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!