Matlab Help for 3D Graphing
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to model the Boston Red Sox's and New York Yankees' homeruns over the past 50 years from 1969-2019 and the graph I'm getting is coming out as I want it to. Can somone help fix my code to get the graph right and explain to me the changes they made and why they did it?
x = 0:49;
y = 0:1;
z = [197 203 161 124 147 109 134 134 213 172 194 162 90 136 142 181 162 144 174 124 108 106 127 84 114 120 175 209 185 205 176 167 198 177 238 222 199 192 166 173 212 211 203 165 178 123 161 208 168 208
94 111 97 103 131 101 110 120 184 125 150 189 100 161 153 130 176 188 196 145 130 147 147 163 178 139 122 162 161 207 193 205 203 223 230 242 229 210 201 180 244 201 222 245 144 212 183 241 267 306];
xv = 0:0.05:49;
yv = 0:0.05:1;
[xi,yi] = meshgrid(xv,yv);
zc = interp2(x,y,z,xi,yi,'cubic');
mesh(xi,yi,zc);
surfc(xi,yi,zc);
xlabel('Years')
ylabel('Teams')
zlabel('Number of Homeruns');
title('Homeruns Hit Red Sox vs Yankees 1969-2019')
yt = get(gca,'YTick');
ytklbl = {'Boston Red Sox','New York Yankees'};
ytix = linspace(min(yt),max(yt),numel(ytklbl));
set(gca,'YTick',ytix,'YTickLabel',ytklbl)
xt = get(gca,'XTick');
xtklbl = {'69','70','71','72','73','74','75','76','77','78','79','80','81'
'82','83','84','85','86','87','88','89','90';'91','92','93','94','95'
'96','97','98','99','00','01','02','03','04','05','06','07','08','09'
'10','11','12','13','13','14','15','16','17','18','19'};
xtix = linspace(min(xt),max(xt),numel(xtklbl));
set(gca,'XTick',xtix,'XTckLabel',xtklbl)
[minhr,idxmin]=min(zc(:));
[maxhr,idxmax]=max(zc(:));
[rmin,cmin]=ind2sub(size(zc),idxmin);
[rmax,cmax]=ind2sub(size(zc),idzmax);
text(xv(cmax),yv(rmax),maxhr,{'This is the maximum';'\downarrow'},'HorizaontalAlignment','center','VerticalAlignment','bottom');
text(xv(cmin),yv(rmin),minhr,{'\uparrow';'This is the minimum'},'HorizontalAlignment','center','VerticalAlignment','top');
view(-100,100)
5 comentarios
Respuestas (1)
Tommy
el 3 de Abr. de 2020
The plot:

And the updated code:
x = 0:49;
y = 0:1;
z = [197 203 161 124 147 109 134 134 213 172 194 162 90 136 142 181 162 144 174 124 108 106 127 84 114 120 175 209 185 205 176 167 198 177 238 222 199 192 166 173 212 211 203 165 178 123 161 208 168 208
94 111 97 103 131 101 110 120 184 125 150 189 100 161 153 130 176 188 196 145 130 147 147 163 178 139 122 162 161 207 193 205 203 223 230 242 229 210 201 180 244 201 222 245 144 212 183 241 267 306];
xv = 0:0.05:49;
yv = 0:0.05:1;
[xi,yi] = meshgrid(xv,yv);
zc = interp2(x,y,z,xi,yi,'cubic');
mesh(xi,yi,zc);
surfc(xi,yi,zc);
xlabel('Years')
ylabel('Teams')
zlabel('Number of Homeruns');
title('Homeruns Hit Red Sox vs Yankees 1969-2019')
yt = get(gca,'YTick');
ytklbl = {'Boston Red Sox','New York Yankees'};
ytix = linspace(min(yt),max(yt),numel(ytklbl));
set(gca,'YTick',ytix,'YTickLabel',ytklbl)
xt = get(gca,'XTick');
xtklbl = {'69','70','71','72','73','74','75','76','77','78','79','80','81',...
'82','83','84','85','86','87','88','89','90','91','92','93','94','95',...
'96','97','98','99','00','01','02','03','04','05','06','07','08','09',...
'10','11','12','13','13','14','15','16','17','18','19'};
xtix = linspace(min(xt),max(xt),numel(xtklbl));
set(gca,'XTick',xtix,'XTickLabel',xtklbl)
[minhr,idxmin]=min(zc(:));
[maxhr,idxmax]=max(zc(:));
[rmin,cmin]=ind2sub(size(zc),idxmin);
[rmax,cmax]=ind2sub(size(zc),idxmax);
text(xv(cmax),yv(rmax),maxhr,{'This is the maximum';'\downarrow'},'HorizontalAlignment','center','VerticalAlignment','bottom');
text(xv(cmin),yv(rmin),minhr,{'\uparrow';'This is the minimum'},'HorizontalAlignment','center','VerticalAlignment','top');
view(-100,100)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

