Error using ==> disp and Error in ==> TempArray1 at 6 disp('New B is equal to',D);

1 次查看(过去 30 天)
I wrote two simple m files as follow trying to overwrite the values of B by the values of A. In other words, my intention is to ultimately have B as [1 2 3 4] by rewriting the matrix A to B. The reason that I have utilized two m file is that later on I need to implement such system to another problem in which the main m file has to be run with modified values of B in each step of loop. First m file as: disp('A is [1 2 3 4]'); disp('B is [4 3 2 1]'); A=[1 2 3 4]; B=[4 3 2 1]; D=TempArray2(A,B); disp('New B is equal to',D); Second m files as: function D=TempArray2(s1,s2) s2=s1; D=s2; But I again got another error message as : ??? Error using ==> disp Too many input arguments.
Error in ==> TempArray1 at 6 disp('New B is equal to',D);
Do u know the solution to this problem?

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2011-9-10
disp() is used to quickly display a text or array. You can't combine two together. In your example, use:
disp('New B is equal to');
disp(D);
or use fprintf
fprintf('New B is equal to %f%f%f\n',D);

类别

Help CenterFile Exchange 中查找有关 Communications Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by