scatter plot: x and y vectors must be of the same length -- errors
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
nines
el 3 de En. de 2020
Respondida: Star Strider
el 4 de En. de 2020
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:
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')
0 comentarios
Respuesta aceptada
Star Strider
el 4 de En. de 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.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Electrophysiology en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!