Drawing a 2-D figure in Matlab [closed] - matlab

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Please If anyone can give a hint on drawing this in matlab
( I am not asking for the actual code but just a hint....)

Hard do give a hint, as it is just one line of code.
rectangle('Position',[1,2,5,6])
To actually see the rectangle you need to set the axes limits:
axis equal
xlim([0,8])
ylim([0,9])
Regarding your comment: have a look at this answer which gives a little introduction into the core graphics objects you're lookling for.
Core Graphics Objects
Core graphics objects include basic drawing primitives:
Line, text, and polygon shells (patch objects)
Specialized objects like surfaces, which are composed of a rectangular grid of vertices
Images

To draw an arbitrary figure you can use plot. For example, this draws a trapezoid:
x = [1 7 4 2 1]; %// x coordinates of vertices
y = [1 1 3 3 1]; %// y coordinates of vertices
plot(x,y); %// do the plotting
axis([0 8 0 4]) %// set axis limits
As you se, you specify the vertices and plot (in its default behaviour) joins them with straight lines. You need to specify the first vertex again as a last vertex to close the polygon.

Related

time series plot in MATLAB [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to get my time series plot in the form of second plot below. But I do not know how this bar chart in MATLAB can be obtained for a series time. Has anyone ever had such an experience to guide me? The first figure is an example of a time series plot that I want to plot in the form of the second plot.
It should be noted that the first image is with a simple plot command in MATLAB.
http://www.sidc.be/silso/datafiles#total
link address for data.i plot a daily data of sunspot number from the link that it's like the first curve here. now i want to have a curve like the second pic here for any time series data.
You can make a stacked bar chart with two different sets of bars, then make the bottom bar white so it is invisible, then the top sets of bars will look like your above plot. Here is some sample code and the plot it makes
bar_bottom = [0.5, 2, 1.5];
bar_height = [4, 5, 3];
x = 1:3;
h = bar(x, [bar_bottom; bar_height], 'stacked');
set(h(1),'EdgeColor', 'w', 'FaceColor', 'w') % set bottom bar to be white (invisible since background is white)
set(h(2),'FaceColor', 'c', 'EdgeColor', 'w', 'BarWidth', 1)
line(x, bar_bottom + 0.5 * bar_height, 'LineWidth', 2)

Confusion matrix image in matlab [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to make a confusion matrix for some classification problem.
So far, I've managed to make a 10 by 10 matrix that stores the accuracy of my estimation for classification problem.
Now I want to make a 10 by 10 square image(?) that has a darker color when the number in that location of the matrix has a higher number. (Ranges from 0 to 100)
I've never done graphics with Matlab before.
Any help would be greatly appreciated.
Thanks.
I would use image. For example:
img = 100*rand(4,4); % Your image
img = img./100*64; % The `image` function works on scale from 0->64
image(img); % or `image(img')` depending on how you want the axis
colormap('grey'); % For grey scale images
axis equal; % For square pixels
Or for inverted colours you can change the one line to:
img = 64-img./100*64;

how to reduce the number of regions based on colors in this image? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I need to show this image in 3 colors , by giving each similar color region one color. The result should be in 3 colors without escape for any region in the image.
how i can combine the small regions with same color in one region as possible limits
i need to reduce the number of regions.
thanks
I hope you already have the regions yourself, else you'd be asking a too broad question, as those super-pixels are hard to get.
While I wont write thw code for you, ill give you the steps needed.
Find the average color of each region. Remember to work in HSV, and not RGB. Also, remember that H is circular. [1 0 0] and [0 0 0] are the same color in HSV.
Perform a classification of those colors, by, for example, KNN. Create 3 clusters, and compute the centroids of those clusters. Those will be your 3 colors
Convert the 3 centroids and the mean color of each superpixel to L*a*b* color space. This space is defined as "closest color is most similar color". Basically, compute the euclidean distance of each of the mean values of the superpixels to the 3 "class colors". The minimum distance class will be the one corresponding to that superpixel.
You can find help on each of these steps easily if you Google/search Stackverflow.
The nice thing of coding it properly is that you can try more colors, say 5 or 6, to see if the image/classification is better. 3 seem like to few colors.

computing Histogram of oriented gradients on log polar bins [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to compute histogram of oriented gradient on my image. But I don't want to divide the image to regular square blocks. I'm going to divide the image to uniform log polar bins(like bins in shape context or bins like here ) and then on each bin(block) the histogram of gradient with 8 orientation is computed.
But
1) I don't know how to divide the image to log polar bins. Can I use shape context? Or even the above link for partitioning to these bins?
2) how can I compute HOG on this bins since available codes(in matlab, OpenCV and EmguCV) use square bins? I have no idea.
What you are describing sounds pretty much like the C-HOG (circular HOG) features in the original HOG paper. The only difference wrt typical hog is the shape of the bins. I think it would be best to:
iterate over the pixels
calculate the circular bin number for each pixel
add the contribution of the gradient at the pixel to the histogram corresponding to the bin number
A good starting point would be the pseudo-matlab-code in this answer: https://stackoverflow.com/a/10115112/1576602

How to draw a 3D arrow/vector in MATLAB? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I would like to add some arrows to a 3D surface plot to indicate important directions, similar to this one (from povray)
Different colors would be great and a threedimensional letter like the X in the image even more.
The function 3D arrow plot at the MATLAB file exchange actually does this:
Meanwhile https://ww2.mathworks.cn/matlabcentral/fileexchange/14056-arrow3 turned up, which might be even better but I haven't tested it...
I used something similar to your approach thta could be a start for you: here is an example of the code:
q=[0 1 0 1];
q=qnorm(q);
x = q(1) / sqrt(1-q(4)*q(4))
x =
0
y = q(2) / sqrt(1-q(4)*q(4))
y =
1.0000
z = q(3) / sqrt(1-q(4)*q(4))
z =
0
quiver3(0, 0, 0, x, y, z)
It is a quaternion that I normalize and convert to axis components in order to draw it 3D. I also would like to be able to draw it 3D like the picture you posted.