Vectorization help, separating an array into multiple arrays
Show older comments
Hi. I'm having some trouble with vectorization.
Basically I have an excel sheet with data from a weather model. The model outputs data for separate "weather groups" (locations). So first I made some code that finds where each new weather group starts.
if true
num=xlsread('SampleWxData.xlsx');
CurrentWxGroupStart = 1;
AllWxGroupsStart = 1;
while (find(num(:,1)>num(CurrentWxGroupStart,1),1))
NextWxGroupStart = find(num(:,1)>num(CurrentWxGroupStart,1),1);
AllWxGroupsStart = horzcat(AllWxGroupsStart, NextWxGroupStart);
CurrentWxGroupStart = NextWxGroupStart;
end
NumberOfWxGroups = size(AllWxGroupsStart,2);
end
I then read the excel sheet again to get the raw data
if true
[rad,time,all]=xlsread('SampleWxData.xlsx');
end
This part all works. The format of the excel sheet is 3 columns: WxGroup, time, radiation
Now, I want to create a three dimensional array, concatenating each weather groups data. Basically I have a long list of all the data now, and I want to separate it out by the weather group.
I know how to do this with a for loop, but I want to vectorize it.
I know the following can get me the first Weather Group
if true
AllWxGroups = (all(AllWxGroupsStart(1,1):AllWxGroupsStart(1,2)-1,:));
end
So I first added the ending point to the variable AllWxGroupsStart and tried
if true
x=1:size(AllWxGroupsStart,2)-1;
AllWxGroups = all(AllWxGroupsStart(1,x):AllWxGroupsStart(1,x+1)-1,:);
end
But that just returned the first Weather Group again. Not sure why not...I thought putting x there would just do the same thing as before except cycle through all values of x, but I guess not.
Let me know if you need any more clarification.
1 Comment
Kyle Chudler
on 3 Jan 2013
Edited: Kyle Chudler
on 3 Jan 2013
Accepted Answer
More Answers (0)
Categories
Find more on Weather and Atmospheric Science 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!