Scatterplot arrays with different number of elements and tracing the trendline

1 view (last 30 days)
So... I have 3 arrays, one is called "M_IRI" (1 row and 36 columns) and the other is called "EVAN_DSUV_FSDN_100" (3 rows and 36 columns) and "RESTO_100" (3 rows and 36 columns) respectively . My problem is happening when I try to make a scatterplot... It just doesn't work.
I need to make this scatterplot to get the trend line between these values, one of my colleagues said to do it separately and then just plot the average of these 2 3x36 matrices, but statistically, this is wrong, so I need to somehow get these 2 trend lines, one between M_IRI and EVAN_DSUV_FSDN_100 and between M_IRI and RESTO_100.
Is there any way to do this?
  2 Comments
Jon
Jon on 14 Sep 2023
Edited: Jon on 14 Sep 2023
It isn't at all clear to me what you are trying to do from your description. Exactly which variable do you want plotted in the y-axis (vertical) of your scatter plot(s) and which variables do you want as the x-axis (horizontal).
For example if you wanted to plot the second row of EVAN_DSUV_FSDN_100 (y-axis) vs M_IRI (x-axis), you could use
plot(M_IRI,EVAN_DSUV_FSDN_100(2,:),'o')
xlabel('M_IRI')
ylabel('EVAN_DSUV_FSDN_100 ')
You could also use
scatter(M_IRI,EVAN_DSUV_FSDN_100(2,:))
xlabel('M_IRI')
ylabel('EVAN_DSUV_FSDN_100 ')
Jon
Jon on 14 Sep 2023
Reading your question more carefully, and in particular your last sentence I think I understand what you are trying to do. I would recommend using @Star Strider's answer

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 14 Sep 2023
Edited: Star Strider on 14 Sep 2023
One option is to reshape the (3x36) arrays into (i08x1) (column) vectors and duplicate ‘M_IRI’ to match by just triplicating it as a column vector. (I chose column vectors because this simple linear regression requires them.) Then do the regression.
Try this —
M_IRI = rand(1,36);
EVAN_DSUV_FSDN_100 = randn(3, 36)+[0;1;2];
RESTO_100 = randn(3, 36)+[5;6;7];
B1 = [repmat(M_IRI(:), 3, 1) ones(36*3,1)] \ reshape(EVAN_DSUV_FSDN_100.', [], 1)
B1 = 2×1
0.1971 0.8247
B2 = [repmat(M_IRI(:), 3, 1) ones(36*3,1)] \ reshape(RESTO_100.', [], 1)
B2 = 2×1
-0.2154 6.1815
figure
scatter(M_IRI, EVAN_DSUV_FSDN_100)
hold on
plot([min(M_IRI) max(M_IRI)], [min(M_IRI) 1; max(M_IRI) 1]*B1, '-r')
hold off
figure
scatter(M_IRI, RESTO_100)
hold on
plot([min(M_IRI) max(M_IRI)], [min(M_IRI) 1; max(M_IRI) 1]*B2, '-r')
hold off
These are just random data so the trends are not impressive, however this should work with your data. You can also use polyfit and polyval to do the regression.
EDIT — Corrected typographical errors.
.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!