How to plot the following figure via matlab hist function?
Group 1: [10, 10, 20]; and Group 2: [15, 10, 8]. Each group consists of three algorithms' running times.
HIST is not a solution to your problem. Please try to look for the bar function
A sample snippet may look like
g1 = [10,10,20];
g2 = [15,10,8];
algStr = sprintfc('Algorithm %d',1:3);
bar(categorical({'Group1','Group2'}),[g1;g2])
legend(algStr)
You will also need to learn how to tweak the axes of the figure to match exactly to your sample graph. But I think I will leave it for you to find out.
It's not something you can do with the hist function, but something you can do with the bar function:
bar([10, 10, 20; 15, 10, 8])
Related
I want to plot just the first 50 points of the following function in MATLAB and I'm having difficulty finding out how to do this, I genuinely cannot find the command or much that is similar online. Can anyone help me out with this? Thank you in advance for all the help, anything is appreciated.
>> p=pi;
>> x=[0:0.1:4*p];
>> y = exp(-0.4*x).*sin(x);
>> plot(x,y), plot(x(1:50)) %%%this is one of my attempts
>> title ('MATLAB PRACTICE');
>> xlabel('x-Axis');
>> ylabel('y-Axis');
>> grid on
You are close, but it is instructive to break the problem into steps.
Think of it this way: you want to first select the first 50 values of x and y, and then plot those.
You can do that like so:
xSubset = x(1:50);
ySubset = y(1:50);
plot(xSubset, ySubset);
The syntax x(1:50) can be used to select a portion of x (or any vector).
We can accomplish the same thing without creating the temporary vectors, which may be desirable because it is more concise (and less typing):
plot(x(1:50), y(1:50));
I am trying to simulate a code which is on the official MATLAB website, but I cannot get the same output.
This is the code:
c = categorical({'apples','oranges','pears'});
prices = [1.23 0.99 2.3];
bar(c,prices)
This is the correct output which is on the MATLAB website:
This is the output that I get in my MATLAB:
The c array, which is apple, orange and pears is not showing in my MATLAB output. Why don't I get the same output?
My MATLAB version is R2016a.
You can try the following workaround (as mentioned here):
prices = [1.23 0.99 2.3];
bar(prices)
set(gca,'xticklabel',{'apples','oranges','pears'});
So, you get rid of categorical and switch to the gca function, that allows you to change axis labels.
I want to draw a line on a graph to find the intersection point with another line. However, there's no response after I executed the script below. May I know what is the problem and how can I solve it?
x=1:2^20;
y2=2^24;
plot(x,y2);
Thanks!
What you want is to plot a line on 2^24. However, there are too many points for you computer probably, and you run out of memory
I am guessing that you'll need to plot your other inequality as well.
Something like
x=1:100:2^20;
% As Zoran and others suggested, You may not want all the points!
% It is too much memory
y2=2^24*ones(size(x)); % This ones is optional, but its good to know what you are doing (personal opinion)
plot(x,y2);
hold on
y1=(x+1).*log(x);
plot(x,y1);
However, you are still not there!
Another solution, which does not rely on plotting:
>> f = #(x) (x+1)*log(x)-2^24;
>> soln = fzero(f,1e6)
soln = 1.1987e+006
>> f(soln)
ans = 3.7253e-009
So your intersection point is at 1.1987e6.
Apparently,you have too many points for x, 2^20
Have to wait program to calculate, or plot,for example, every 100th point
This solution works for Matlab
x=1:100:2^20;
y2=2^2;
plot(x,y2,'o');
There is one more and maybe a bit smarter way: if you want to solve ((k+1)(ln k)<2^24) as you've commented above, use fsolve function to get just solution of an equation(!). Then use that solution to specify the area of your interest, so you won't have to plot the domain of 2^20.
(All functions are continuous so you don't have to worry about any wild singularities. Just examine the neigborhood of ks for which (k+1)(ln k)-2^24=0.)
There are 2 column vectors A,B containing 100 data values. I intend to plot the MSE(mean square error ) using the following code but all I get is a single dot instead of a line plot. Please help how to go about it.
A=x(:,1);
B=y(:,1);
er=(double(A)-double(B)).^2;
row_er=mean(er,2); % variable changed
plot(row_er);
This script works fine.
A = randn(10, 1);
B = randn(10, 1);
er=(double(A)-double(B)).^2;
row_e=mean(er,2);
plot(row_e)
Probably you have a typo (row_er)
row_e=mean(er,2);
plot(row_er);
Please notice that the command mean returns the mean of a vector (which is one simple value). If you want to plot plot the square error then you just plot((A-B).^2).
But... If you are interested in plotting the mean square error with, say, 10 samples average, you will have a plot with only 10 points (100 / 10 because each 10 data points are averaged to give you one point).
The command would be
plot(blkproc((A-B).^2,[10,1],'mean'))
hope it helps.
I want to plot a single [2,-2,0] in Maple.
I am trying to use command:
pointplot3d([2, -2, 0], axes=normal, symbol=cross)
it does not work(maybe because pointplot3d is for a list of points). Help please.
It worked for me, provided that I either invoked it as plots:-pointplot3d(...) , or plots[pointplot3d](...) , or as pointplot3d(...) only after having loaded the plots package by with(plots).
The default color and size may not be to your liking. Here's a screenshot (Maple 15.01, Windows 7),
plots[pointplot3d]([[2, -2, 0]], axes=normal,
symbolsize=20, symbol=cross, color=red);
You mentioned about its being a single point. Wel, in all of Maple 13.02, 14.01, 15.01, and 16.00 it also works as plots[pointplot3d]([[2, -2, 0]],...) which is a list of lists.