i have used this code but it only displays data against coloumn1 (if I enter any field from coloumn1 then it displays the whole Row of that). I want it, like if I enter data from second or any other coloumn then it should display the whole row of that too.
in = input('F');
[num,txt,raw] = xlsread('soil silt.csv');
p = strcmpi(in,raw(:,2));% Compare user input string with entries in the Excel sheet
rowNum = find(p==1)%Get Row number
tab = readtable('soil silt.csv'); % see doc for more options
tab(ismember(tab.(1), 'Stage 1'), :) % the row at which the input str matches the first table's column

답변 (1개)

Subhajyoti Halder
Subhajyoti Halder 2023년 6월 28일
편집: Subhajyoti Halder 2023년 6월 28일

0 개 추천

Hi Aiman,
It is my understanding that it is required to display all the rows in the table, where any column matches with the input keyword.
Here, I have implemented the same using ‘readtable’ function ’ in MATLAB R2023a on a sample csv file.
In the below code, itis iterating over the rows and storing the row-indices of the table that have any column matching the given token.
in = 'Calcuta';
raw = readtable('sample_sheet.csv')
raw = 13×3 table
Name Dep IIM _________________________ __________________________ _____________ {'Abhiman Das' } {'Economics' } {'Ahmedabad'} {'Chinmay Tumbe' } {'Economics' } {'Ahmedabad'} {'Jeevant Rampal' } {'Economics' } {'Ahmedabad'} {'Errol D'Souza' } {'Economics' } {'Calcuta' } {'Rakesh Basant' } {'Economics' } {'Calcuta' } {'Sanket Mohapatra' } {'Economics' } {'Calcuta' } {'Viswanath Pingali' } {'Economics' } {'Calcuta' } {'Devasmita Chakraverty'} {'Educational Innovation'} {'Calcuta' } {'Swanand Deodhar' } {'Information Systems' } {'Bangalore'} {'Anand Kumar Jaiswal' } {'Marketing' } {'Bangalore'} {'Arindam Banerjee' } {'Marketing' } {'Bangalore'} {'Hyokjin Kwak' } {'Marketing' } {'Bangalore'} {'Rajat Sharma' } {'Marketing' } {'Bangalore'}
rowNum = [];
p=1;
for i=1:size(raw)
if ismember(in,raw{i,:})
rowNum(p)=i;
p=p+1;
end
end
tab = readtable('sample_sheet.csv');
% the row at which the input str matches the first table's column
tab(rowNum, :)
ans = 5×3 table
Name Dep IIM _________________________ __________________________ ___________ {'Errol D'Souza' } {'Economics' } {'Calcuta'} {'Rakesh Basant' } {'Economics' } {'Calcuta'} {'Sanket Mohapatra' } {'Economics' } {'Calcuta'} {'Viswanath Pingali' } {'Economics' } {'Calcuta'} {'Devasmita Chakraverty'} {'Educational Innovation'} {'Calcuta'}
Note: For numerical value, use ‘ismember(in,raw(i,:))’.
For more details on the ’readtable’, kindly go through the following documentation

카테고리

도움말 센터File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2023년 6월 7일

편집:

2023년 6월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by