필터 지우기
필터 지우기

How to call a specific element of a table

조회 수: 3 (최근 30일)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019년 8월 29일
편집: Andrei Bobrov 2019년 8월 30일
I want to
find the "radius" in which "time" is 2 and p"erhexagon" is 2.1667. There might be more than one radius that matches this criteria.
Any suggestion?
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 8월 29일
편집: KALYAN ACHARJYA 2019년 8월 29일
Have you check here?
Still unable to resolve it, please attach the table.
madhan ravi
madhan ravi 2019년 8월 29일
Learn to attach data as .mat file as shown by Andrei below, attaching a screenshot is useless!

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

채택된 답변

Adam Danz
Adam Danz 2019년 8월 29일
편집: Adam Danz 2019년 8월 29일
Assuming your table is named "T",
% find the rows where time equals 2 and perhexagon equals exactly 2.1667
rowidx = T.time == 2 & T.perhexagon == 2.1667;
% use the row index to get the chosen radii
chosenRads = T.radius(rowidx);
Note that if you have trouble matching the floating point decimals, you may have to build in a tolerance instead of requiring an exact match. Example below.
% Define tolerance
tol = 0.001; %accepted if perhexagon value is +/-tol from target
% find the rows where time equals 2 and perhexagon equals exactly 2.1667
rowidx = T.time == 2 & abs(T.perhexagon - 2.1667)<tol;
  댓글 수: 2
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019년 8월 29일
편집: Zeynab Mousavikhamene 2019년 8월 29일
Thanks.
I tried:
% find the rows where time equals 2 and perhexagon equals exactly 2.1667
rowidx = Acc_cellcount.time == 2 & Acc_cellcount.perhexagon == 2.1667;
% use the row index to get the chosen radii
chosenRads = Acc_cellcount.radius(rowidx);
and it came out:
chosenRads =
0×1 empty double column vector
Adam Danz
Adam Danz 2019년 8월 29일
This is where my "note" comes in at the end of my answer. Your "perhexagon" values aren't really 2.1667. Those are just the first 4 decimal places. So you need to build in a tolerance. For example, accept any rows where perhexagon is within 0.0001 within the target value. I'll update my answer.

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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2019년 8월 29일
편집: Andrei Bobrov 2019년 8월 29일
load data.mat
lo = ismembertol(T{:,{'time','perhexagon'}},[2,2.1667],'ByRows',true,...
'DataScale',[1 .00001]);
out_radius = T.radius(lo);
  댓글 수: 2
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019년 8월 29일
편집: Zeynab Mousavikhamene 2019년 8월 29일
Got this error:
Error using load
Unable to read file 'data.mat'. No such file or directory.
I run for the second time without "Error using load" and I got :
"out_radius =
0×1 empty double column vector"
Tried multiple 'DataScales': [1 .001] or [1 .1] or [1]
all gave empty out_radius.
Andrei Bobrov
Andrei Bobrov 2019년 8월 30일
편집: Andrei Bobrov 2019년 8월 30일
You do not know how to download, sorry.
Exsample my laptop with Ubuntu (I from Russia :) ):
>> load '/home/andrei/Загрузки/data.mat'
>> lo = ismembertol(T{:,{'time','perhexagon'}},...
[2,2.1667],'ByRows',true,'DataScale',[1 .00001]);
out_radius = T.radius(lo)
out_radius =
1
2
>>

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by