How should I extract the data

조회 수: 1 (최근 30일)
Shubham Pathare
Shubham Pathare 2022년 2월 14일
답변: Seth Furman 2022년 2월 28일
for a=1:count_rows
if Tablename.Var1(a,1)<0 && Tablename.Var1(a+1,1)==0
c=a;
end
if Tablename.Var1(a,1)==0 && Tablename.Var1(a,1)<0
c=d;
d=a;
newvar1=['Var1',num2str(count1)];
newvar2=['var2',num2str(count1)];
newvar3=['var3',num2str(count1)];
assignin('caller',newvar1,Var1(c:d,1));
assignin('caller',newvar2,Var2(c:d,1));
assignin('caller',newvar3,Var3(c:d,1));
count1=1+count1;
end
end
I have text file with four columns and few values of one columns are like below and I want to create new table for each set of cells having value 0 and they should be in between positive 1 only(unlined 0). New table should also contains remaining three corresponding values.
Then I need to perform exact same operations (eg.calculating avg) on newly created table. I used the for loop but then it will be difficulat to perform futher operations on newly created varibales as they have dynamic names.
Column 1
1
1
0 -1st new table
0 -1st new table
0 -1st new table
0 -1st new table
1
1
1
0 -ignore
0 -ignore
0 -ignore
-1
-1
-1
-1
0 -ignore
0 -ignore
0 -ignore
1
1
1
0 -Should be in 2nd new table
0 Should be in 2nd new table
0 Should be in 2nd new table
1
1
1
1
  댓글 수: 2
Rik
Rik 2022년 2월 14일
Please attach an example file and post the code you have already tried.
Shubham Pathare
Shubham Pathare 2022년 2월 14일
Pleasee see the updated post

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

채택된 답변

Seth Furman
Seth Furman 2022년 2월 28일
Read tabular text data into a table
t = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/894130/Sample.txt")
t = 31×4 table
Var1 Var2 Var3 Var4 ____ ____ ______ ______ 1 1 1.5907 42.882 1 1.2 1.5937 42.963 1 1.3 1.5967 43.044 1 1.2 1.5997 43.124 0 1.3 1.6027 43.205 0 1.4 1.6057 43.286 0 1.5 1.6087 43.367 0 1.6 1.6117 43.448 1 3 1.6147 43.529 1 2.3 1.6177 43.61 1 2.4 1.6207 43.69 0 2.5 1.6237 43.771 0 3.3 1.6267 43.852 0 3.4 1.6297 43.933 -1 3.2 1.6327 44.014 -1 1 1.6357 44.095
Use logical indexing to extract rows that meet criteria
t(t.Var1 == 0, :)
ans = 13×4 table
Var1 Var2 Var3 Var4 ____ ____ ______ ______ 0 1.3 1.6027 43.205 0 1.4 1.6057 43.286 0 1.5 1.6087 43.367 0 1.6 1.6117 43.448 0 2.5 1.6237 43.771 0 3.3 1.6267 43.852 0 3.4 1.6297 43.933 0 1.3 1.6447 44.337 0 1.4 1.6477 44.418 0 1.5 1.6507 44.499 0 2.3 1.6627 44.823 0 2.4 1.6657 44.904 0 1 1.6687 44.984

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by