简体   繁体   中英

Plotting the vectors for correspoding index in Matlab

I have two vectors A = [12 21 23 14 15 36 63 63 .... ] ( of 100 values ) and another vector B = [1:1:100] .

Now i want to plot a bar graph such that i can plot the values of A on Y axis for corresponding value from B vector on X -axis. Eg to plot 12 for 1, 21 for 2 , 23 for 3 and so on.

I tried doing hist(A,B) but it did not work. Let me know some another approach.

Perhaps you meant to use a regular bar plot:

>> bar(B,A)

If you have too many values on the x-axis, this might produce a nicer plot:

B = 1:100;
A = randi(100,size(B));

bar(B,A,'histc');
xlim([1 100])

bar_plot

hist(A,100)

produces a histogram of A, the second parameter is the number of bins that you want. There's some examples in the documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM