Programming

1 visualizzazione (ultimi 30 giorni)
Fire
Fire il 25 Mar 2011
Hello All,
I want to create a loop. My question is, for example
1) I have a depth data, MD = 1070 1071 1074 1075 1076.1 1078 1080 1085 1087 1090
2) In other side I have image data, SRAMi which consists of 10 rows and 6 columns. its just contains 1 and 10 inside the data.
in my 1st column it has values: 1 1 10 10 10 10 10 1 1 1 in my 3rd column it has values: 1 1 1 1 10 10 10 10 1 1
as you can see the data are not similar in 1st and 3rd column. Also, MD and SRAM are two different datas which are in my workspace
I want to create a loop like when there is a change from 1 to 10 in my 1st column it should pick the values from my depth.
for example, my 1st column values shows there is a change in 3rd step, where it changes from 1 to 10 and at 7th step it changes again from 10 to 1. At this point it should pick the corresponding depth values. in this example it is 1074 and 1080.
The same way it should also pick from my 3rd column.
My aim is to find the difference in depth where there is a change (1 to 10 or 10 to 1) in 1st column and 3rd column.
for example, just to say the first change in 1st column corresponds to the depth 1074 and the 1st change in 3rd column corresponds to the depth 1076.1 so the difference will be 1076.1-1074 = 2.1m.
I am new to Matlab so if some one can help me, it will be very useful for me. It's also an emergency for me to move forward with my problem. Thanks in advance
Ela

Risposta accettata

Sarah Wait Zaranek
Sarah Wait Zaranek il 25 Mar 2011
If I understood your question correctly, I would propose the following:
First, find the places where 1 changes to 10 or 10 to 1. The easiest way to do this is to diff the column(find differences between the rows). Then you can use logical indexing to extract out the right values from your depth data. Once you have the two sets of depth data, you can just subtract them.
See code below:
% Setting up some example data
SRAMi = zeros(10,6);
SRAMi(:,1) = [1 1 10 10 10 10 10 1 1 1];
SRAMi(:,3) = [1 1 1 1 10 10 10 10 1 1];
MD = [1070 1071 1074 1075 1076.1 1078 1080 1085 1087 1090];
% Using diff to find difference between rows
diff1 = [0; abs(diff(SRAMi(:,1)))];
diff3 = [0; abs(diff(SRAMi(:,3)))];
% Extracting depths where difference is 9 using logical indexing
depth1 = MD(diff1 == 9);
depth3 = MD(diff3 == 9);
% Subtracting depths
diffdepth = depth3 - depth1;
Logical indexing is probably the trickiest thing to understand here. If you are interested in reading more about it, see link below.
  2 Commenti
Sarah Wait Zaranek
Sarah Wait Zaranek il 25 Mar 2011
Probably can skip MD(diff1 == 9) and use MD(logical(diff1) like suggested in other answer.
Fire
Fire il 29 Mar 2011
Tats perfect and tats wat I expect. I am late in reply bcoz im sick but it really helps me a lot.

Accedi per commentare.

Più risposte (1)

Anathea Pepperl
Anathea Pepperl il 25 Mar 2011
You can probably use the diff function to find the step changes, so that for the 1st column:
mark = diff(column1);
index = [0, logical(mark)];
You need to add a 0 to the beginning of index since diff will return an N-1 vector, given an input with N values.
depth_values = MD(index);
Once you have the depth values saved, you can use the diff function again to determine the changes in depth.
  1 Commento
Fire
Fire il 29 Mar 2011
Thanks a lot, your logical indexing is really helped me a lot. I got the solution too ! :) thanks lot for your help

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by