How separate data from a table and convert every column in vector if this seáration depends on the label 'D' or 'E'?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Cristian camilo García Castaño
il 23 Giu 2020
Commentato: Star Strider
il 28 Giu 2020
How I separate a table if I need the corresponding values from 'D' and 'E' in diferents vectors
angle1 angle2 angle3 label
--------- ----------- -------- ----------- --------
111 90 50 'D' ...
321 80 50 'E'
121 70 50 'E'
222 70 50 'D'
333 80 50 'D'
I need obtain the vector for every colum depends of the label 'D' and 'E' for instance
angle1E = [321 121]
angle1D = [111 222 333]
angle2E = [80 70]
angle2D = [90 70 80]
I tried first change the colum 4 in a categorical, and after this use a called in the colum all D but i dont understand well
close all;
clearvars;
clc;
%% import data for angle
angle = readtable('angulos33.txt');
%% Variable
A11 = angle(:,1); %%angle at 0 h
A22 = angle(:,2); %%angle at 24 h
A33 = angle(:,3); %% Angle at 48 h
A44 = angle(:,4); %%etiqueta interno "D" externo "E"
A44 = categorical(angle.Var4('D'))
0 Commenti
Risposta accettata
Star Strider
il 24 Giu 2020
Try this:
C = { 111 90 50 'D'
321 80 50 'E'
121 70 50 'E'
222 70 50 'D'
333 80 50 'D'}; % Copy-Paste Data
T = cell2table(C, 'VariableNames',{'angle1','angle2','angle3','label'}); % Create Table
G = findgroups(T{:,4}); % Could Also Use ‘unique’
Angles = accumarray(G, (1:numel(G)).',[], @(x){T(x,:)}); % Group Data Into Separate Tables
then defining:
AnglesD = Angles{1}
AnglesE = Angles{2}
produces:
AnglesD =
3×4 table
angle1 angle2 angle3 label
______ ______ ______ _____
111 90 50 {'D'}
222 70 50 {'D'}
333 80 50 {'D'}
AnglesE =
2×4 table
angle1 angle2 angle3 label
______ ______ ______ _____
321 80 50 {'E'}
121 70 50 {'E'}
To extract them from the tables:
Angle1D = AnglesD.angle1.'
Angle1E = AnglesE.angle1.'
producing:
Angle1D =
111 222 333
Angle1E =
321 121
and similarly for the others.
.
2 Commenti
Più risposte (1)
Takumi
il 24 Giu 2020
Using strcmp function, you can get the index that matches the specified string.
You can then use the index to find the corresponding value.
angle1 = [111;321;121;222;333];
angle2 = [90;80;70;70;80];
angle3 = [50;50;50;50;50];
label = {'D';'E';'E';'D';'D'};
yourtable = table(angle1,angle2,angle3,label);
yourtable.angle1(strcmp(yourtable.label,'D'))
0 Commenti
Vedere anche
Categorie
Scopri di più su Tables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!