how can I plot single x-value of type string against multiple y-values of type double?

3 views (last 30 days)
Good evening!
How can I plot string-type x-value against multiple double-type y-values?
I want to plot a 2D-point diagramm of number of repetitions (string data for x-axis, for example '40 repetitions') against result datas (double for y-axis, for example 0.55, 0.66, 0.57, 0.67 ...). Number of results correspond to the number of repetitions.
It looks like this:
'40 repetitions' [0.55 0.66 0.57 0.67 ...] ; --> 40 result datas
'10 repetitions' [0.67 0.78 0.65 ...] ; --> 10 result datas
'4 repetitions' [0.86 0.65 ...] ; --> 4 results datas
and so on. So that in the end we see the scattering of result points for each of repetition scheme.
Thank You!
Edit:
I've tried with plot and this is how I want to present the result datas. But instead of "1", "2", and "3" itu should be "40 repetitions", "10 repetitions", "4 repetitions" and so on...
  3 Comments
Fajri
Fajri on 3 Mar 2016
thank you Kirby!
I've managed to set all the results as black-filled circles and the arithmetical mean for each repetition as red-filled circles.
I have one more questions though: How can I display Legend that says the black circles as "results value" and the red circles as "mean value"?
I very appreciate your help :)

Sign in to comment.

Accepted Answer

Kirby Fears
Kirby Fears on 2 Mar 2016
Edited: Kirby Fears on 2 Mar 2016
You could visualize the data in many ways. Here's a simple way scatter the data and label each series.
% using random data
data = {rand(1,40),rand(1,10),rand(1,4)};
dataLabels = {'40 reps','10 reps','4 reps'};
% plotting scatter plot
hold on;
for i = 1:numel(data),
scatter(repmat(i,1,length(data{i})),data{i},'*');
end
hold off;
ax = gca;
ax.XTick = 1:numel(dataLabels);
ax.XTickLabel = dataLabels;
ax.XLim = [0 numel(dataLabels)+1];
  3 Comments
Fajri
Fajri on 3 Mar 2016
thank you Kirby!
I've managed to set all the results as black-filled circles and the arithmetical mean for each repetition as red-filled circles.
I have one more questions though: How can I display Legend that says the black circles as "results value" and the red circles as "mean value"?
I very appreciate your help :)
Kirby Fears
Kirby Fears on 4 Mar 2016
Edited: Kirby Fears on 4 Mar 2016
I'm glad that worked for you, Fajri.
As you stated, you're now plotting two kinds of things in one chart: the "results values" and "mean values".
The legend() command in Matlab allows you to name each series in the order in which they were plotted. So the easiest way to make the legend you're looking for is to plot a "results value" and a "mean value" as the first two calls to scatter. Then you can call legend() with two names to display.
Expanding on my example above, you can achieve this by scattering the "results value" and "mean value" one after the other inside the for-loop.
% plotting scatter plot
hold on;
for i = 1:numel(data),
scatter(repmat(i,1,length(data{i})),data{i},'*');
scatter(i,mean(data{i}),'*');
end
hold off;
legend({'all values','mean value'});
I'll leave the marker color choices to you.
Hope this helps.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!