Plotting random number in a line
25 次查看(过去 30 天)
显示 更早的评论
Hi Matlab Team,
I have X = rand(1,100), and I want to plot X such that points be in X axis. At the moment, when I use plot(X, '*'), we have index 1 to 100 on x-axis and X is in the vertical axis. This is not, what I want !!!
Thanks
1 个评论
DGM
2024-8-26
编辑:DGM
2024-8-26
If you only specify a single vector input in the call to plot(), then that vector is plotted with respect to its indices. That's the way plot() works. You need both X and Y data in order to have a plot. If you only give it one vector, then it's treated as Y-data, and the X-data is implied.
If you're trying to plot X-data, then what do you expect the Y-data to be? Whatever it is, you need to supply it.
采纳的回答
Voss
2024-8-26
If you want to plot points on the x-axis, specify the y-coordinates as zero.
X = rand(1,100);
Y = zeros(1,100);
plot(X,Y,'*')
4 个评论
Aquatris
2024-8-26
meanValue = 0.5; % mean value
stdValue = 0.15; % std value
sizeMatrix = [1 100]; % size of the random number matrix/vector
X = normrnd(meanValue,stdValue,sizeMatrix); % normally distrubeted random numbers
X = max(min(X,1),0); % clip the values at 0 and 1
hist(X,20)
Voss
2024-8-26
Another option:
xmin = 0.4;
xmax = 0.6;
N = 100;
X = xmin+(xmax-xmin)*rand(1,N);
Y = zeros(1,N);
figure
subplot(2,1,1)
plot(X,Y,'*')
xlim([0 1])
subplot(2,1,2)
hist(X)
xlim([0 1])
Another option:
xmin = 0.4;
xmax = 0.6;
N = 100;
X = xmin+(xmax-xmin)*randi([0,1],1,N);
Y = zeros(1,N);
figure
subplot(2,1,1)
plot(X,Y,'*')
xlim([0 1])
subplot(2,1,2)
hist(X)
xlim([0 1])
更多回答(1 个)
John D'Errico
2024-8-26
编辑:John D'Errico
2024-8-26
What is it that you want then? A plot requires TWO axes, TWO variables to be plotted, typically we might plot x versus y.
My first guess is you MIGHT want to see a histogram. I'll generate a few more points, so the histogram will look as you would expect.
X = rand(1,10000);
histogram(X,10)
Or, perhaps you might want to see just a set of vertical lines, one line for each point.
figure
X = rand(1,100);
xline(X,'r')
If you want to see something different, if these plots do not give you the information you need, then instead of telling us what you DON'T want to see, you needed to explain what you DID want to see. Otherwise all we can do is make wild guesses.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!