help-octave
[Top][All Lists]

## RE: plot octave graph by running .m file problem

 From: Allen.Windhorn Subject: RE: plot octave graph by running .m file problem Date: Tue, 13 Oct 2015 19:01:12 +0000

```Manpreet,

> -----Original Message-----
>
> I am facing a another problem during plotting of graph. I have searched
> for plotting, But my simple code plot graph. But I want to create graph for
> below code. It did not plot any single point on graph. Guide me

I'm not one of the experts, but here is what I think.  I have incorporated

function k=value(doverA,aoverA)
up=(1-(aoverA)^2-(2*aoverA*doverA)-(doverA)^2);
down=(aoverA*doverA+(doverA)^2);
k=up/down;
end

% I'm not sure what this is supposed to do, but it seems to work all
% right. But it only takes two scalar numbers and produces another
% scalar number.
%
% The thing about Octave is that it wants to work with arrays and
% matrices in order to function efficiently.  So you should write your
% function so it takes two arrays and produces a third array, giving
% you the whole plot all at once.  Read more about Octave to find out
% how to do this.

%value(0.03,0.5)
for aoverA=0.05:0.05:0.3 % this sets aoverA to a single number for
% each loop iteration
for doverA = 0.03:0.01:0.3 % this sets doverA to a single number for
% each loop iteration.
% so for the first iteration, aoverA is equal to 0.05 and doverA is
% equal to 0.03, and when you are finished, aoverA and doverA are both
% equal to 0.3.
k=value(doverA,aoverA) % 168 values are calculated for k, but none
% of them are ever
used
plot(doverA,aoverA, 'r-') % this plots one point 168 times, erasing the
% previous plot each
time.
endfor
endfor

% Here you are trying to do Octave's work for it.  But what you are
% doing is (a) calculating a value for k for each loop iteration, and
% then throwing it away (you never use k for anything), and (b)
% plotting a bunch of graphs, each with one point.  The plot function
% takes an array of numbers for x and another for y, and plots them
% (like you are trying to do below).
%
% What you might want is:
%
% aoverA = 0.05:0.05:0.3;
% doverA = 0.03:0.01:0.3;
%
% But then aoverA will have 6 points and doverA will have 28 points,
% so you can't plot them together.  Probably you want to do:
%
% aoverA = 0.05:0.05:0.3;
% doverA = 0.03:0.01:0.3;
% k = value(aoverA, doverA);
%
% ...producing k which will be a matrix of points on a surface, not a
% single value.  Then you can plot k scaled to the axes aoverA and
% doverA.

title('Curve Plotting');
xlabel('a/A');
ylablel('d/A');

% These need to come AFTER the plot statement I think.

plot([0; aoverA(:,1)], [0; doverA], '-ro'); hold on

% This actually works; it plots a nice straight line between (0, 0) and
% (0.3, 0.3), in red, with circles at each end.  Probably not what you
% intended, but what you told it to do (since aoverA and doverA are both
% equal to 0.3, your two arrays to plot are x axis [0, 0.3], and y axis
% [0, 0.3].  The (:,1) part selects all the rows in the first column of
% aoverA.  There is only one row and one column, so you just get the
% value, which is 0.3).
%
% I am unable to figure out from your code what you are trying to do,
% so can't help you more than that.  The function (which never does
% anything) seems intended to produce a surface plot, which needs a
% different plot command and some preprocessing.  Try "help meshgrid",
% "help surf", and "help surface".  Look at the examples of surface
% plots, like the sombrero plot.

Regards,
Allen

```