MATLAB: How to query data

query

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.

Best Answer

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.
Related Question