How to find intersection between row and column from Excel file

조회 수: 1 (최근 30일)
Huda Mohammed
Huda Mohammed 2022년 2월 24일
댓글: Arif Hoq 2022년 2월 24일
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

답변 (1개)

Arif Hoq
Arif Hoq 2022년 2월 24일
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
Huda Mohammed
Huda Mohammed 2022년 2월 24일
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 2022년 2월 24일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by