From: Anamika on 3 Jun 2010 20:49 Sorry about that us. I accidently posted the query twice. Thanks for your input. ~Mika "us " <us(a)neurol.unizh.ch> wrote in message <hu9geg$k9m$1(a)fred.mathworks.com>... > "Anamika " <Anamika.Darwin(a)gmail.com> wrote in message <hu9eb2$2di$1(a)fred.mathworks.com>... > > Hello, > > > > How do you refer to the elements of an array that you load in a for loop? > > > > In the code below, for the subplot section how can the variable be set so that it changes every time from X1 to X2 and so on until the loop gets over. > > > > Thanks for your input! > > ~Mika > > > > % Data file containing coordinates to be plotted > > > > load MyDataSet.dat > > > > % Loaded data gets assigned > > > > X1 = MyDataSet(1:616,2); Y1 = MyDataSet(1:616, 3); > > X2 = MyDataSet(617:1131,2); Y2 = MyDataSet(617:1131, 3); > > X3 = MyDataSet(1132:1655,2); Y3 = MyDataSet(1132:1655, 3); > > X4 = MyDataSet(1656:2050,2); Y4 = MyDataSet(1656:2050, 3); > > .... > > .... > > .... > > X20 = MyDataSet(6661:6900,2); Y20 = MyDataSet(6661:6900, 3); > > > > % Sublot routine > > for n=1:20 > > h(n)=subplot(20,1,n); > > plot(X1,Y1, 'r'); % HOW TO REFER ARRAY ELEMENTS HERE? > > hold on; > > end > > don't dup OPs(!)... > the answer's here at > > http://www.mathworks.com/matlabcentral/newsreader/view_thread/283836 > > us
From: dpb on 3 Jun 2010 20:46 dpb wrote: .... > x = mydataset; % Shorten var name just for demo/less typing... > blks = [615, 515, 524, ...]; % blocksize for each segment to plot > i1 = 1; % first point > for idx=1:length(blks) > h(idx)=subplot(20,1,idx); % probably find this too many, but... > i2 = i1+blks(idx); % end point this block > plot(x(i1:i2,2),x(i1:i2,3)); > x1 = x2+1; % 1st next block one past end this one > end > Typo in updating block indices corrected... for idx=1:length(blks) h(idx)=subplot(20,1,idx); % probably find this too many, but... i2 = i1+blks(idx); % end point this block plot(x(i1:i2,2),x(i1:i2,3)); % here... i1 = i2+1; % 1st next block one past end this one end drat I _hate_ it when that happens... :( --
From: dpb on 3 Jun 2010 21:09 Anamika wrote: > Thanks dpb. > The breakpoints are entirely dependent on a each data set I deal with. > Just one question, for the last line, I think you meant to re-initialize > i1 and not x1 (typo?). When I changed and applied, I got plot I want. .... Yes, I had just posted the correction...sorry about that; fortunately it was a pretty obvious one... --
First
|
Prev
|
Pages: 1 2 Prev: Undefined symbols - mx API functions Next: Elements of an Array in For Loop |