scatter plot: x and y vectors must be of the same length -- errors

7 visualizzazioni (ultimi 30 giorni)
hello everyone!
i am trying to make a categorical scatter plot that has the x axis equal 'cortex' and 'ventricle' and then the y axis have two different groups (young and old) for each x-axis category. i want to plot a matrix that has each mean timeseries of each individual subject like this:
Screen Shot 2020-01-03 at 12.41.32 PM.png
however, i am getting the error that "Error using scatter (line 78)
X and Y must be vectors of the same length."
the code works with an overall mean of the subjects (e.g. cortex old, cortex young, etc.) but isn't working with the matrix of means of the individual subjects, and i was wondering if anyone had any advice? thank you in advance!!!
ts_cortex_matrix_seventy = timeseries([d_c_ts_1 d_c_ts_2 d_c_ts_3 d_c_ts_4 d_c_ts_5 d_c_ts_6 d_c_ts_7 d_c_ts_8 d_c_ts_10])
ts_mean_cortex_seventy = mean(ts_cortex_matrix_seventy)
y_seventy = [ts_mean_cortex_seventy ts_mean_ventricle_seventy] %the mean of each subject ind subject elderly
y_young = [ts_mean_cortex_young ts_mean_ventricle_young] %the mean of each subject ind subject young
x = categorical({'cortex'; 'ventricle'});
figure;
ax1 = subplot(3,1,1)
hold on
scatter (x, y_seventy)
scatter (x, y_young)
hold off
legend('seventy', 'young')
sgtitle('Young and Elderly Subjects - Cortex and Ventricle Average')
xlabel('Subject')
ylabel('ts average n=10 young, old')

Risposta accettata

Star Strider
Star Strider il 4 Gen 2020
It is probably not possible to use scatter with a categorical variable.
You can do what I believe you want using plot (and a tweak):
figure
plot([1 2], y_seventy, 'pb', 'MarkerFaceColor','b');
hold on
plot([1 2], y_young, 'pr', 'MarkerFaceColor','r')
hold off
set(gca, 'XTick',[1 2], 'XTickLabel',{'cortex'; 'ventricle'});
xlim([0 3])
Make appropriate changes to get the result you want.

Più risposte (0)

Categorie

Scopri di più su Teaching Resources in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by