How should I extract the data
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Shubham Pathare
am 14 Feb. 2022
Beantwortet: Seth Furman
am 28 Feb. 2022
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 Kommentare
Akzeptierte Antwort
Seth Furman
am 28 Feb. 2022
Read tabular text data into a table
t = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/894130/Sample.txt")
Use logical indexing to extract rows that meet criteria
t(t.Var1 == 0, :)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Database Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!