# X and Y matrix of size:1x68.this code works well.but when command " plot(X,Y,'ro', x,y,'-b',xt,yt,'--g');" shifted outside for loop; plot for last value of xt and yt How to store all values of xt and yt outside for loop?

1 view (last 30 days)
vaishali on 11 Jun 2014
Commented: vaishali on 14 Jun 2014
Value of X=[272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
]
and Value of Y=[310 310 310 310 310 310 310 310 310 310 310 311 311 311 311 310 309 310 311 313 313 314 314 314 314 313 314 313 314 314 314 314 314 314 314 315 315 315 315 313 315 316 316 315 315 315 316 316 316 316 316 316 316 316 315 315 315 316 317 317 317 318 319 318 319 319 319 320
]
if true
X0data = X;
for i=1:length(X0data)
X0 = X0data(i);
Y = x9';
n = 1000; % 100 or some higher number for nice curves
f = 0.1; % this defines the length of the tangent
x = linspace(min(X),max(X),n);
y = interp1(X,Y,x,'spline');
xt = X0+(0.1*(max(X)-min(X))*[-1 0 1]);
m = diff(y)./diff(x);
m = [m, m(end)]; % so just add one at the end
k = min([find(x >= X0,1,'first'), length(x)]);
yt = y(k) + m(k)*(0.1*(max(X)-min(X))*[-1 0 1]);
plot(X,Y,'ro', x,y,'-b',xt,yt,'--g');
hold on; % to allow multiple plots on same figure
end % code
end

Mahdi on 11 Jun 2014
Edited: Mahdi on 11 Jun 2014
Change the the lines to:
xt(i,:) = X0+(0.1*(max(X)-min(X))*[-1 0 1]);
and
yt(i,:) = y(k) + m(k)*(0.1*(max(X)-min(X))*[-1 0 1]);
vaishali on 14 Jun 2014
It results error msg: Index exceeds matrix dimensions.

### Categories

Find more on 2-D and 3-D 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!

Translated by