Hi
I want to use the size function to check the output array, I expect 12×2 matrix but it shown "rows=8" which is less. Which lead to the next step when I want to use the rows is display an error said Index in position 1 exceeds array bounds (must not exceed 8).
Here is my code. Please let me know if you knwo what 's wrong with it. Thank you.
%print every set of number that sum to target value t
clear;clc;%input an matrix
a=input('Enter a matrix:');%check the size of the matrix
n=length(a);%create an matrix
matrix=[];%loop through
for r=1:n for i=1:n if a(r)+a(i)==12 matrix(r,1)=a(r); matrix(r,2)=a(i); end endend%check the size of the matrix
[rows,colns]=size(matrix);disp(rows);disp(colns);for k=1:rows if matrix (k,1)>=matrix(k,2) matrix(k,:)=[]; end enddisp(matrix);%% when I discard the "check matrix and delect rows part" is display a 12* 2 matrix like this
Best Answer