How to find intersection between row and column from Excel file

1 view (last 30 days)
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
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
Huda Mohammed on 24 Feb 2022
thank you for your support but I dont think you get my point
I dont want the inputs to be numbers I want the user to input variable to get the intersection between them
from a to j is the column name also from a to j is the row name
for example after the user entering c for row and f for column he will get 0
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
Arif Hoq
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

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!