Clear Filters
Clear Filters

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

1 view (last 30 days)
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?

Answers (1)

Fangjun Jiang
Fangjun Jiang on 10 Sep 2011
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);

Community Treasure Hunt

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

Start Hunting!