Reading all text from specific cell from .csv file.

조회 수: 4 (최근 30일)
Shivam Upadhyay
Shivam Upadhyay 2020년 2월 17일
댓글: Shivam Upadhyay 2020년 2월 24일
Actually I am new to matlab. I actually want to read specific code from the excel sheet(which is one column having all the specific code) and then want to print the information associated with that specific code(which is in another column). So what should I do.
Below is the sample csv data.
Specific Code DTC_display DTCType Information
'0x000100' 'P0001-00' 'CD' 'Fuel Volume Regulator "A" Control Circuit/Open'
'0x000200' 'P0002-00' 'CD' 'Fuel Volume Regulator "A" Control Circuit Range/Performance'
'0x000300' 'P0003-00' 'C' 'Fuel Volume Regulator "A" Control Circuit Low'
'0x000400' 'P0004-00' 'C' 'Fuel Volume Regulator "A" Control Circuit High'
Simply. If user enter specific code then I will search from the first column and then if I found the inputted value in first column then I will print the information associated with it(present in the column with header Information).
  댓글 수: 4
Jakob B. Nielsen
Jakob B. Nielsen 2020년 2월 17일
CSV is comma separated values, but it looks like yours are tab separated. Can you try to attach the file, so we can see exactly what format we are working with?
Shivam Upadhyay
Shivam Upadhyay 2020년 2월 17일
CSV File is attached in this comment.

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

채택된 답변

Giuseppe Inghilterra
Giuseppe Inghilterra 2020년 2월 21일
편집: Giuseppe Inghilterra 2020년 2월 21일
Hi,
try to run following code, you should obtain what you have asked:
close all
clear all
clc
filename = 'dtc_table.csv';
T = readtable(filename,'ReadVariableNames',false);
T.Properties.VariableNames = {'SpecificCode' 'DTCDisplay' 'DTCType' 'Information'};
prompt = 'Enter Code: ';
UserCodeInput = input(prompt,'s'); %ask user for specific code as string
[r,c] = size(T);
CodeIsFound = false;
for ii = 1:r
if strcmp(UserCodeInput,T.SpecificCode{ii,1}) % if code is found display information
CodeIsFound = true;
disp(T.Information{ii,1})
end
end
if CodeIsFound == false % if code is not found at all display "not found"
disp('Specific Code not found')
end
The user input is considered as a string and strcmp function is used to compare strings. If code is found, associated information is displayed.
Example:
Hope this helps.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by