Problems with plotting in Matlab

Hey, I've got a problem plotting a function in Matlab.

I first run this:

format long f = inline('-x.^2');

for i = 0:10 [I(i+1) h(i+1) tid(i+1)] = trapets(f,0,1,2^i); end

trunk = I - log(2);

hold on grid on

plot(log(h),log(trunk),'r+')

t = -7:0; c = polyfit(log(h),log(trunk),1); yy = polyval(c,t); plot(t,yy) grid off hold off

koefficienter = real(c)

and after that I run this file:

hold on

plot(h,trunk,'r+:','linewidth',2)

axis([0 0.6 0 0.0014])

Thing is, I don't get any errors, and the plot windows pops up with axes and all, but there is no graph to be found. It's just an empty window with two axes.

Anyone got any ideas?

Edit: Okay, so I'm new to this site and couldn't find the reply button, so I add a reply here instead.

@woodchips : I just realized that I hadn't given you all the information for this problem.. Sorry about that, anyhow I would really appreciate it if someone had the time to help me with this, it would seriously make my week.

This is the part I accidentally left out:

function [ I,h,tid ] = trapets( f,a,b,n )

h=(b-a)/n;

tic; I=(f(a)+f(b));

for k=2:2:n-2

I = I+2*f(a+k*h);

end

for k = 1:2:n-1

I = I + 4*f(a+k*h);

end

I = I * h/3;

tid = toc;

end

Edit 2: So, I think that the graph I'm seeking is actually getting plotted in the first code that I wrote, the problem is that the variabe 'I' is not changing, which I expect it to do, although the variabels 'n' and 'h' do change. If 'I' was working correctly, I would probably get the right graph (hopefully). Any ideas, anyone?

-------------Problems Reply------------

Unfortunately the home computer I had with Matlab on it died the other day so I can't test anything. First thing I can think of if to simply run step by step through the code and see if the results of the math are what you are expecting. For instance Matlab was primarily made and runs as a matrix calculator if I recall correctly. As such most of the simple math doesn't function as it would punching it in a calculator. An example would be that 2^i needs to be 2.^i to operate correctly in some cases. Same with .* and ./ to use the singular scalar verses the matrices math.

The best way to find out what is going wrong is to iterate through the math a few times to ensure that it is being performed as expected. Once that is verified then you can move on to looking at plotting formatting.

Category:matlab Views:0 Time:2011-06-04
Tags: matlab plot

Related post

  • Rotating a plot in MATLAB? 2011-02-23

    Hi I have just obtained an x-y plot in MATLAB of the sine curve and I wish to rotate this plot by 90 degrees counter clockwise. How do I do this? --------------Solutions------------- In the figure you have plotted, click 'View'->'Camera Toolbar'.

  • How to make 1-D plots in MATLAB? 2011-04-21

    How can I make plots in MATLAB like in below? I won't need labels, so you can ignore them. I tried using normal 2D plot, by giving 0 to y parameter for each data points. It does help, but most of the plot remains empty/white and I don't want that. Ho

  • How to change font size of right axis of Pareto plot in Matlab 2015-02-11

    I am trying to bold the right side y axis for a Pareto plot in Matlab, but I can not get it to work. Does anyone have any suggestions? When I try to change the second dimension of ax, I get an error: "Index exceeds matrix dimensions. Error in pcaClus

  • Changing axes and color of plots in Matlab 2010-05-06

    How do you get rid of the axes and dotted line grids when you plot in Matlab? Also, how do I make subplots of subplots. Since that's probably not very clear, what I mean is the following... Let's say I have a 10x10x10 .mat file, so I open each of the

  • How to make a log plot in matlab 2010-08-11

    Is it possible to make a plot in matlab that does not actually take the logs of the values? I'm plotting wide ranges of values and when I try to make a log plot of them, those below 1 become negative. I would just like it to plot the values on a log

  • How to add arrows to line plots in Matlab? 2010-09-30

    I would like to add arrows to a plot of a line in Matlab to illustrate flow. The arrows would ideally be on the line pointing in the direction of the line. Is this possible? --------------Solutions------------- In order to draw an arrow in Matlab, us

  • How to plot closed loop response Bode plot in Matlab? 2011-05-04

    I want to plot a closed loop response Bode plot. But as we know Bode plot gives you open loop response. So how do I plot a closed loop response Bode plot in Matlab ? --------------Solutions------------- As we know Bode plot gives you open loop respon

  • How do I get a tabled form of values of a probability plot in matlab? 2011-05-15

    I am trying to find the probability distribution of some stochastic data. I can generate the plot in matlab but would find it more useful if i could get the values in tabled format so i can do a monte carlo simulation. --------------Solutions--------

  • Custom contour plot in MATLAB 2012-03-28

    I want to create a contour plot in MATLAB, as in the second example on this page: ContourPlot[Cos[x] + Cos[y] == 1/2, {x, 0, 4 Pi}, {y, 0, 4 Pi}] As you can see, they are plotting only the lines for which f(X, Y) == some_value. Another issue I have i

  • How to copy (to clipboard) only significant part of a plot in Matlab? 2013-06-24

    How to copy (to clipboard) only significant part of a plot in Matlab? Without that large gray margins Matlab loves so much? Is it possible to populate clipboard from Matlab command line? --------------Solutions------------- As far as programmatically

  • How do I set the default linestyle for plots in MATLAB? 2010-11-23

    I have an array of data that I would like to plot temp=0.5*rand(500,10); [~,offset]=meshgrid(1:500,1:10); figure(101) plot(temp+offset') How can I set the line style to automatically change to the next style once the line colours have been through on

  • Getting intermediate points generated by plot() in MATLAB 2010-12-15

    I've got a series of XY point pairs in MATLAB. These pairs describe points around a shape in an image; they're not a function, meaning that two or more y points may exist for each x value. I can plot these points individually using something like plo

  • Drawing a surface plot in Matlab similar to one obtained using Gnuplot? 2011-03-04

    Update: Link to my test dataset I have some data like this: 10.0 11.0 0.5 10.0 12.0 0.5 10.0 14.5 0.5 10.0 16.0 0.5 10.0 18.5 0.5 10.0 19.0 0.5 10.0 19.5 0.5 10.0 20.0 0.5 Using Gnuplot, I could plot the following picture: using the following script

  • 3D body plot in matlab ( volume visualization ) 2012-01-26

    I have little or no experience with volumetric data in MATLAB, I need to complete next task: I have 3 vectors ( rows ): x_ = vector(1:smpl:max_row,1); y_ = vector(1:smpl:max_row,2); z_ = vector(1:smpl:max_row,3); that are samples from large 3 columns

  • How to find the x-intercept of a plot in Matlab 2012-04-02

    I know there must be a really simple answer to this question, but I just can't seem to find it. (Guess I'm probably Googling the wrong terms.) I am plotting some data in Matlab using the plot(x, data) function. I want to find the x-intercept(s) of th

  • Disable plots in Matlab 2012-04-12

    I have some programs written in Matlab that I need to run several times for some reasons (debugging, testing with different input, etc...) But, there are a lot's of graphs that are plotted by the programs and its various functions such that everytime

  • How to plot a 3D plot in MATLAB? 2009-11-27

    I have three parameters x,y and t. But the problem is my file structure. My files are named as: e_x_y.txt t_x_y.txt where e_x_y.txt has the error for particular values of x and y and t_x_y.txt has corresponding time values. I need to plot the values

  • Problem storing plot objects in a list in R 2009-11-30

    I asked this question yesterday about storing a plot within an object. I tried implementing the first approach (aware that I did not specify that I was using qplot() in my original question) and noticed that it did not work as expected. library(ggplo

  • Why does a circle plotted in MATLAB appear as an ellipse? 2009-12-07

    I wonder in MATLAB how I would plot a circle and show it correctly instead of by default showing it as an ellipse. I guess it has something to do with the local coordinate system in the axis. --------------Solutions------------- You can use the comma

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.199 (s). 11 q(s)