I thought i had a code that worked but i noticed a tiny error, and ive been banging my head on a brick wall sleeplessly trying to get it to work for days.
Heres my code, i hate it, it doesn't work, if you reckon you can fix it please tell me otherwise just skip this bit and as I've decide to start again.
function TempSalplot(datafile)datafile=importdata(datafile);A=datafile.data;figure;col = flipud(parula(round(max(datafile.data(:,28)))));%depth,distance,salinity,temp are in column 28,2,14,11 of datafile respectively;
for d=[1:3:max(datafile.data(:,28))]; %max is around 16
for avd=[1:length(A(:,28))]; if A(avd,28)>d-0.5 & A(avd,28)<d+0.5; B(avd,1)=A(avd,2); B(avd,2)=A(avd,14); B(avd,3)=A(avd,11); B(all(B==0,2),:)=[]; end [M,~,z] = unique(B(:,1),'stable'); M(:,2) = accumarray(z,B(:,2),[],@mean); M(:,3) = accumarray(z,B(:,3),[],@mean); plot(M(:,2),M(:,3),'o-','color',col(d,:)); hold on; end xlabel('Salinity (psu)'); ylabel('Tempurature (degC)'); h=colorbar('ticks',[1:3:round(max(datafile.data(:,28)))]); h.Label.String=('Depth (m)'); caxis([1,max(d)]); colormap(col);end
Essentially i have 4 columns of interest say (a,b,c,d). I would like to average b and c over certain ranges of d. so I would only have as many b,c pairs for a certain d range as there are a values. Then I would like to plot that and redo it for another a range.
data=0 15 33 0.50 15 32 0.80 16 32 1.30 13 34 1.610 13 34 0.610 14 35 1.010 16 36 1.510 12 33 1.925 13 34 0.625 12 33 0.925 12 34 1.625 12 36 1.9
What I think I need is a for loop.
1st iteration for 0<d=<1 (d=0.5).
M=0 15 32.5 0.510 13.5 34.5 0.525 12.5 33.5 0.5plot(M(:,2),M(:,3));
then repeat for d=1.5 (1<d=<2) however some of the later iteration for example (10<d=<11) have no measurements for certain values of a so should be shorter than the earlier iterations and therefore plot fewer points.
Any help on this is really appreciated , this has been a nightmare for me, thinking I had it working so many times.
Best Answer