简体   繁体   中英

How can create matrix output in MATLAB?

I am a kind of begginner for MATLAB and ı cant output my matrice out of the for loop. Can u please help?

clc; clear;
i=1;
j=1;
A=[i;j];
for i=1:1:3
    for j=1:1:4
   A=input('Enter A[i;j] value: ');
   fprintf('A[%g;%g]= %g     ',i,j,A);
    end
end
fprintf('Your matrice is : ');
disp(A);

Most likely you wish to store each value inputted by indexing array A in the for-loop using the iteration variables i and j in the form of A(i,j) . Also preallocating the size of array A with empty zeroes may also help with speed. Upon each loop the value returned from the input() function will be stored in cell (i,j) → (row,column) coordinates/indices of matrix A .

clc; 
clear;

Number_Of_Rows = 3;
Number_Of_Columns = 4;
A = zeros(Number_Of_Rows,Number_Of_Columns);

for i=1:1:Number_Of_Rows
    for j=1:1:Number_Of_Columns
        A(i,j) = input('Enter A[i;j] value: ');
        fprintf('A[%g;%g]= %g\n\n',i,j,A(i,j));
    end
end

fprintf('Your matrix is:\n');
disp(A);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM