how can I arrange the answer into an array?

my code is:
allData = xlsread('C:\in.xlsx');
%time vector and a column array of temperatures
timeVec = allData(:,1);
tempVecs = allData(:,2:end);
%Find the peak time of all temperatures
[maxTemps, maxIndices] = max(tempVecs);
timeVec(maxIndices);
%Find the times that temperature increases
for i =1:5;
for j=200:50:850;
firstIndex = find(tempVecs(:,i) > j, 1, 'first');
lastIndex = find(tempVecs(:,i) > j, 1, 'last');
a=timeVec(firstIndex);
b=timeVec(lastIndex);
residence=b-a;
end
end
Output is like
residence =
82.6500
residence =
73.6500
residence =
63.366
residence =
52.3000
residence =
40.5167
residence =
26.2000
.............
total 70 data.
each column has 14 data point. I want to arrange the residence time in a one file that has 5 column and each column contains 14 data. How can I do that? Any one can help me. A very good guy help me to do the above code. thank good guy.

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 31 Août 2012
Modifié(e) : Azzi Abdelmalek le 31 Août 2012
allData = xlsread('C:\in.xlsx');
%time vector and a column array of temperatures
timeVec = allData(:,1);
tempVecs = allData(:,2:end);
%Find the peak time of all temperatures
[maxTemps, maxIndices] = max(tempVecs);
(maxIndices);
% initialise a counter
count=0;
%Find the times that temperature increases
for i =1:5;
for j=200:50:850;
count=count+1;
firstIndex = find(tempVecs(:,i) > j, 1, 'first');
lastIndex = find(tempVecs(:,i) > j, 1, 'last');
a=timeVec(firstIndex);
b=timeVec(lastIndex);
%store a vector residecnce 1x70
residence(count)=b-a;
end
end
%reshape a vector residence
residence=reshape(residence,14,5)

5 commentaires

Tan Has
Tan Has le 31 Août 2012
thanks. cool
Hi Azzi, I face a problem. When I have less data point such as for j i choose 200:50: 850. but if I don't have 750, 800, 850 in the column so the find actually give the results of 200 to 700 and for 750, 800 and 850 is zero or nan. how could i do that? Now I am getting an error
??? Improper assignment with rectangular empty matrix.
Error in ==> find_time_temp at 19 residence(count)=b-a;
when the column does not have data for above a temperature.
Azzi Abdelmalek
Azzi Abdelmalek le 3 Sep 2012
i did'nt understand your question, what is equal to nan?
Tan Has
Tan Has le 3 Sep 2012
I mean no value. in the code i represent column number and j represent value range. for an example fir i=1 the first column has max value 1100. so 850 value for j falls within the range but if the second column has max value 767 then 800 and 850 is out of max value. so in that case i need to consider j= 200: 50: 750. which is i am doing now manually by changing the j after observe the max value. Can I do that automatically?
u cane add nan value to tempVecs and some values to timeVec
n=length(tempVecs)
if n<850
tempVecs(end+1:850)=nan
timeVec(end+1:850)= timeVec(end)+1: timeVec(end)+850-n
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur WLAN Toolbox dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by