How to find intersection between row and column from Excel file
Show older comments
Hello;
I have this code I want to ask the user to enter 2 inputs one is the row name and the other is the column name then the system will find the intersection between them for Example
b intersection with b gives 0
below is My code:
x=xlsread('book2.xlsx')
a0=input('Enter previous GCAS=')
a=input('Enter GCAS1=')
if x(a0,a)==1
disp('No wash')
else
disp('wash')
end
below is book2 file:
a b c d e f g h i j
a 1 1 1 1 1 1 1 1 1 1
b 1 0 1 0 1 0 1 0 1 0
c 1 1 0 1 1 0 1 1 0 1
d 1 1 1 0 1 1 1 0 1 0
e 1 1 1 1 0 0 0 1 0 1
f 1 1 1 1 0 0 0 0 0 1
g 1 1 1 1 0 0 0 0 1 0
h 1 1 1 1 0 0 0 0 0 1
i 1 1 1 1 0 0 1 1 0 0
j 0 1 0 1 1 0 1 1 0 1
Answers (1)
Arif Hoq
on 24 Feb 2022
A=readtable('Book6.xlsx','ReadVariableNames',false);
AA=table2array(A);
nrows = 11;
ncols = 11;
for c = 1:ncols
for r = 1:nrows
if r == c
AA{r,c} = 0;
end
end
end
AA
7 Comments
Huda Mohammed
on 24 Feb 2022
Huda Mohammed
on 24 Feb 2022
I dont find that error in my code. for giving user input try this.
A=readtable('Book6.xlsx','ReadVariableNames',false);
AA=table2array(A);
nrows = input('Enter the row number:');
ncols = input('Enter the column number:');
for c = 1:ncols
for r = 1:nrows
if r == c
AA{r,c} = 0;
end
end
end
AA
Huda Mohammed
on 24 Feb 2022
Arif Hoq
on 24 Feb 2022
or you can use this code
A=readtable('Book6.xlsx','ReadVariableNames',false);
% AA=table2array(A);
AA=A{2:end,2:end};
nrows = input('Enter the row number:');
ncols = input('Enter the column number:');
for c = 1:ncols
for r = 1:nrows
if r == c
AA{r,c} = 51;
end
end
end
AA
Huda Mohammed
on 24 Feb 2022
Arif Hoq
on 24 Feb 2022
try this:
A=readtable('Book6.xlsx','ReadVariableNames',false);
% AA=table2array(A);
AA=A{2:end,2:end};
nrows = input('Enter the row number:');
ncols = input('Enter the column number:');
% nrows={'a','b','c','d','e','f','g','h','i','j'};
% ncols={'a','b','c','d','e','f','g','h','i','j'};
for c = 1:11
for r = 1:11
if nrows=='a' & ncols=='a'
AA{1,1} = 0;
elseif nrows=='b' & ncols=='b'
AA{2,2} = 0;
elseif nrows=='c' & ncols=='c'
AA{3,3} = 0;
elseif nrows=='d' & ncols=='d'
AA{4,4} = 0;
elseif nrows=='e' & ncols=='e'
AA{5,5} = 0;
elseif nrows=='f' & ncols=='f'
AA{6,6} = 0;
elseif nrows=='g' & ncols=='g'
AA{7,7} = 0;
elseif nrows=='h' & ncols=='h'
AA{8,8} = 0;
elseif nrows=='i' & ncols=='i'
AA{9,9} = 0;
elseif nrows=='j' & ncols=='j'
AA{10,10} = 0;
end
end
end
AA
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!