Find value(string) in specific line

조회 수: 4 (최근 30일)
주희 박
주희 박 2022년 8월 31일
댓글: 주희 박 2022년 9월 3일
Hi, I attached example like below. And I want to get a value in #cup. In Example, It gonna be 332.
a=12345
apple= 3333
sky=2412
#cup = 332
#water=827
#paper=099
I have many data so I can't get these values by click respectively .
Additionaly, #cup is in different line by data. So i can't find the value if I use find(example(4,:))
Can I get values in #cup using matlab?

채택된 답변

KSSV
KSSV 2022년 8월 31일
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1112505/Example.txt') ;
idx = contains(T.(1),'cup') ;
T(idx,:)
ans = 1×2 table
Var1 Var2 ________ ____ {'#cup'} 332
find(idx)
ans = 4
  댓글 수: 1
주희 박
주희 박 2022년 9월 3일
Thank yo so much. I'm always indebted to you for your help.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 8월 31일
data = readcell('Example.txt')
data = 6×2 cell array
{'a' } {[12345]} {'apple' } {[ 3333]} {'sky' } {[ 2412]} {'#cup' } {[ 332]} {'#water'} {[ 827]} {'#paper'} {[ 99]}
row = contains(data(:, 1), 'cup')
row = 6×1 logical array
0 0 0 1 0 0
value = data{row, 2}
value = 332
  댓글 수: 1
주희 박
주희 박 2022년 9월 3일
Thank you so much. It also so helpful to me!

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

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by