Run Two Scripts over Single Chart

3 views (last 30 days)
Dima
Dima on 16 Jan 2012
Hello!) I was wondering if there is an easy way to run two similar scripts one after another so that their output is placed on the same chart. lets say I have 222.m scrip and 333.m scrip...I tried this code in teh scrip called TWO
figure(1);hold on;
222.m
333.m
and it gives off the followign error:
??? Attempt to reference field of non-structure array.
Error in ==> TWO at 2
222.m
Thanks!

Accepted Answer

Dima
Dima on 16 Jan 2012
thanks for the reply...here is a more expanded example of combining scripts. I have two scripts named chart1.m and chart2.m as follows:
%chart1
x = 0:.2:20;
y = sin(x)./sqrt(x+1);
y(2,:) = sin(x/2)./sqrt(x+1);
y(3,:) = sin(x/3)./sqrt(x+1);
plot(x,y)
and chart2:
%chart2
x = -pi:.1:pi;
y = sin(x);
plot(x,y)
I try to run these two codes one after another and have their output recorded on one chart:
%combined charts
figure(1);hold on;
chart1.m
chart2.m
and still I get the followign error:
Warning: Direct access of structure fields returned by a function call (e.g.,
call to chart1) is not allowed. See MATLAB 7.10 Release Notes, "Subscripting Into Function Return Values" for details.
> In combinedcharts at 2
??? Attempt to reference field of non-structure array.
Error in ==> combinedcharts at 2
chart1.m
I wonder what do you think is causing this error?
Thanks!
  2 Comments
Chandra Kurniawan
Chandra Kurniawan on 16 Jan 2012
I wrote
figure(1);hold on;
chart1
chart2
And it works just fine on my machine
Dima
Dima on 16 Jan 2012
works for this scrip combination...but what about if I have two larger scripts each of which create their own figure(1)..I mean how do I continue plotting on the figure (1) that was created by the first scrip after that script is finished and the next is started? because with the larger scripts it looks like the figure is recreated when the second script is started...
thanks a lot!)))

Sign in to comment.

More Answers (2)

Ilham Hardy
Ilham Hardy on 16 Jan 2012
Have you compile and debug the 222.m? It seems the problem lies on the shadowing parameter. Based on the error message you need to check the parameter 'TWO' on 222.m script (lines #2).
Check as well your workspace wheteher the parameter 'TWO' is still correct or accidentally overwritten.

Ilham Hardy
Ilham Hardy on 16 Jan 2012
For calling a function (which reside on current path) you just need to use the filename, without file extension.
Try alter your combined chart fun to: %combined charts figure(1);hold on; chart1 chart2
HTH;IH

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!