I want to assign weighting values to geolochemical samples contained within matrix "rawdata" based on the latitude where the rocks were collected (latitude is in 1st column, chemical data in remaining columns). To do this, I have a matrix "Weight_Latbin" where the 1st column has latitude values and the other columns contain weighting values that should be assigned to any sample collected between that lat and the latitude of the next row. These would be in a new matix called "Weights_all" (the ist column would keep the latitude value of the 1st column of rawdata).
For example (simplified):
raw data= [40.55 .. .. ; 40.33 .. ..;....]Weight_Latbin= [40.25 0.80 0.75; 40.50 0.66 0.40; 40.75 0.25 0.90; ...]
Because the latitude of the 1st row of rawdata(1,1)=40.55 is BETWEEN Weight_latbin(2,1)=40.5 and Weight_latbin(3,1)=40.75, I want the 1st row of Weights_all(1,2:end) to have the values of Weight_Latbin(2,2:end).
In the end, for this example, Weights_all= [40.55 0.66 0.40; 40.33 0.80 0.75;..].
This is what I tried:
Weights_all=zeros(size(rawdata));for ii=1:size(rawdata,1) for jj=1:size(Weight_Latbin,1) if rawdata(ii,1)>=Weight_Latbin(jj,1)& rawdata(:,1)<Weight_Latbin(jj+1,1) Weights_all(ii,2:size(Weight_Latbin,2))=Weight_Latbin(jj,2:size(Weight_Latbin,2)); end endend
I am very new to matlab, and I can't get this to work! Please help! (using Matlab 7.10.0 R2010a)
Best Answer