error using vertcat
Afficher commentaires plus anciens
Hey, I need this for university, and I cant figure out whats wrong.. Appreciate your help.
X0 = input ('Nuo, iveskite, X0 ===> ');
Xn = input ('Iki, iveskite, Xn ===> ');
Xh = input ('Zingsnis, iveskite, Xh ===> ');
A = input ('Iveskite konstanta A ===> ');
nx = 0;
for xv = X0:Xh:Xn
nx = nx + 1;
X(nx) = xv;
if ( xv <= 9)
Y(nx) = ((sqrt(xv^3)/((xv-1)*(xv-3)))+15*A/xv+1);
elseif (xv <= 21)
Y(nx) = ((A^4/16)+5*xv^3);
else
Y(nx) = (14-(sqrt(A)/3*xv^2));
end
end
disp( '+----------------+----------------+');
disp( '| X | Y |');
disp( '+----------------+----------------+');
for ix = 1:nx
str_x = num2str( X(ix), '%10.4f');
str_y = num2str( Y(ix), '%10.4f');
disp( [ '| ', blanks( 18-length(str_x)),str_x, ' | ',
blanks( 10-length(str_y)), str_y, ' |'] );
end
disp( '+------------+------------+');
str = num2str ( X0, '%10.4f');
disp( ['| X0 = ', blanks( 18-length(str)), str, ' |']),
str = num2str( Xn, '%10.4f');
disp( ['| Xn = ', blanks( 18-length(str)), str, ' |']),
str = num2str( Xh, '%10.4f');
disp( ['| Xh = ', blanks( 18-length(str)), str, ' |']),
str = num2str( A, '%10.4f');
disp( ['| A = ', blanks( 18-length(str)), str, ' |']),
disp( '+-------------------------+');
plot( X, Y);
and it comes out like this:
??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Please, suggest something :]
1 commentaire
Walter Roberson
le 14 Juin 2012
Which line is the error occurring on?
Réponses (1)
Andrei Bobrov
le 14 Juin 2012
X = input ('input X in form : (first : step : last) -> ');
X = X(:);
A = input ('input constant A -> ');
t1 = X <= 9;
t2 = X <= 21 & ~t1;
t3 = ~(t1|t2);
Y = zeros(size(X));
Y(t1) = sqrt(X(t1).^3)./ ((X(t1)-1).*(X(t1)-3)) + 15*A./X(t1)+1;
Y(t2) = A^4/16+5*X(t2).^3;
Y(t3) = 14-sqrt(A)/3*X(t3).^2;
c = cell2mat(strcat({'| '},num2str(X,'%0.4f'),{' | '},num2str(Y,'%0.4f'),{' |'}));
n = regexp(c(1,:),'\|');
N1 = char('-'*ones(1,n(end)-n(1)));
N1(n) = '+';
N2 = char(' '*ones(1,n(end)-n(1)));
N2(sort([floor(diff(n)/2)+n(1:end-1),n])) = '|X|Y|';
disp(N1);disp(N2);disp(N1);disp(c);disp(N1);
plot(X,Y)
grid on
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!