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?

조회 수: 2 (최근 30일)
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

답변 (1개)

Mahdi
Mahdi 2014년 6월 11일
편집: Mahdi 2014년 6월 11일
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]);
  댓글 수: 3
Mahdi
Mahdi 2014년 6월 12일
Change the xt and yt in the plot function to xt(i,:) and yt(i,:)
vaishali
vaishali 2014년 6월 14일
It results error msg: Index exceeds matrix dimensions.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by