double to table, create new tabel and add data to existing table with different properties

조회 수: 14 (최근 30일)
Hello,
I have a Matlab table for which I carry out many individual calculations as can be seen in the code. the results are columns and tables in double format. I'm having a hard time putting the data back together in a table. I would like a separate table for BHQ, HQextrem, HQ5000 and HQ 10000 with the following data
  • colums 1:6; PP_D colums 1:6; with column names OID, FKM, Lage, x, y, z
  • colums 7; ...MWH name: Maximalewasserhöhe
  • colums 8; ...MWA name:Maximaler Wasseranstieg
  • colums 9; ...MWR name: Maximaler Wasserrückgang
  • colums 10;...FD name: Maximale Überflutungsdauer
  • colums 11: 152; ...WH names: WH Time 0:142
  • colums 153: 295: ... WA names WA Time 0:142
Thanks for your help
here the code and the data:
%% Bearbeitung Punkte
clc
clear all
clear workspace
load ('PP_D.mat')
PP_D_new = removevars(PP_D, {'OID_','FKM','Lage'});
PP_D_string = table2array(PP_D_new);
PP_D_string(PP_D_string==0)=nan
%% Wasserhöhen
for i=1:151
PP_D_Wasserhoehe (i,:)= PP_D_string([i],[4:513])- PP_D_string(i,3);
end
% PP_D_Wasserhoehe=str2double(PP_D_Wasserhoehe);
D_BHQ_WH= PP_D_Wasserhoehe([1:151],[1:83])
D_HQextrem_WH= PP_D_Wasserhoehe([1:151],[84:225])
D_HQ5000_WH= PP_D_Wasserhoehe([1:151],[226:367])
D_HQ10000_WH= PP_D_Wasserhoehe([1:151],[368:509])
%Maximale Wasserhöhen
for i=1:151
D_HQ10000_MWH (i,1)= max(D_HQ10000_WH(i,[1:142]));
D_HQ5000_MWH (i,1)= max(D_HQ5000_WH(i,[1:142]));
D_HQextrem_MWH (i,1)= max(D_HQextrem_WH(i,[1:142]));
D_BHQ_MWH (i,1)= max(D_BHQ_WH(i,[1:83]));
end
%% Anstieg pro Zeitschritt [m/h]
PP_D_Wasserhoehe(isnan(PP_D_Wasserhoehe))=0;
for i=2:510
PP_D_Wasserhoehe_Wasseranstieg(:,i)= PP_D_Wasserhoehe([1:151],i)- PP_D_Wasserhoehe([1:151],i-1);
end
D_BHQ_WA= PP_D_Wasserhoehe_Wasseranstieg([1:151],[1:83])
D_HQextrem_WA= PP_D_Wasserhoehe_Wasseranstieg([1:151],[84:225])
D_HQ5000_WA= PP_D_Wasserhoehe_Wasseranstieg([1:151],[226:367])
D_HQ10000_WA= PP_D_Wasserhoehe_Wasseranstieg([1:151],[368:509])
%Maximaler Wasseranstieg
for i=1:151
D_HQ10000_MWA (i,1)= max(D_HQ10000_WA(i,[1:142]));
D_HQ5000_MWA (i,1)= max(D_HQ5000_WA(i,[1:142]));
D_HQextrem_MWA (i,1)= max(D_HQextrem_WA(i,[1:142]));
D_BHQ_MWA (i,1)= max(D_BHQ_WA(i,[1:83]));
end
%Maximaler Wasserrückgang
for i=1:151
D_HQ10000_MWR (i,1)= min(D_HQ10000_WA(i,[1:142]));
D_HQ5000_MWR (i,1)= min(D_HQ5000_WA(i,[1:142]));
D_HQextrem_MWR (i,1)= min(D_HQextrem_WA(i,[1:142]));
D_BHQ_MWR (i,1)= min(D_BHQ_WA(i,[1:83]));
end
%% Überflutungsdauer
PP_D_Wasserhoehe(isnan(PP_D_Wasserhoehe))=0;
D_BHQ_x= PP_D_Wasserhoehe([1:151],[1:83]);
D_HQextrem_x= PP_D_Wasserhoehe([1:151],[84:225]);
D_HQ5000_x= PP_D_Wasserhoehe([1:151],[226:367]);
D_HQ10000_x= PP_D_Wasserhoehe([1:151],[368:509]);
for i=1:151
D_HQ10000_FD (i,1)= nnz(D_HQ10000_x(i,[1:142]));
D_HQ5000_FD (i,1)= nnz(D_HQ5000_x(i,[1:142]));
D_HQextrem_FD (i,1)= nnz(D_HQextrem_x(i,[1:142]));
D_BHQ_FD (i,1)= nnz(D_BHQ_x(i,[1:83]));
end

답변 (1개)

Abhishek Chakram
Abhishek Chakram 2023년 9월 21일
Hi Frederik Reese,
I understand that you are facing difficulty in creating separate tables for BHQ, HQextrem, HQ5000 and HQ 10000 with your the calculated data.
Here’s the example for doing it:
%% Bearbeitung Punkte
clc
clear all
clear workspace
load ('PP_D.mat')
PP_D_new = removevars(PP_D, {'OID_','FKM','Lage'});
PP_D_string = table2array(PP_D_new);
PP_D_string(PP_D_string==0)=nan
%% Wasserhöhen
for i=1:151
PP_D_Wasserhoehe (i,:)= PP_D_string([i],[4:513])- PP_D_string(i,3);
end
% PP_D_Wasserhoehe=str2double(PP_D_Wasserhoehe);
D_BHQ_WH= PP_D_Wasserhoehe([1:151],[1:83])
D_HQextrem_WH= PP_D_Wasserhoehe([1:151],[84:225])
D_HQ5000_WH= PP_D_Wasserhoehe([1:151],[226:367])
D_HQ10000_WH= PP_D_Wasserhoehe([1:151],[368:509])
%Maximale Wasserhöhen
for i=1:151
D_HQ10000_MWH (i,1)= max(D_HQ10000_WH(i,[1:142]));
D_HQ5000_MWH (i,1)= max(D_HQ5000_WH(i,[1:142]));
D_HQextrem_MWH (i,1)= max(D_HQextrem_WH(i,[1:142]));
D_BHQ_MWH (i,1)= max(D_BHQ_WH(i,[1:83]));
end
%% Anstieg pro Zeitschritt [m/h]
PP_D_Wasserhoehe(isnan(PP_D_Wasserhoehe))=0;
for i=2:510
PP_D_Wasserhoehe_Wasseranstieg(:,i)= PP_D_Wasserhoehe([1:151],i)- PP_D_Wasserhoehe([1:151],i-1);
end
D_BHQ_WA= PP_D_Wasserhoehe_Wasseranstieg([1:151],[1:83]);
D_HQextrem_WA= PP_D_Wasserhoehe_Wasseranstieg([1:151],[84:225]);
D_HQ5000_WA= PP_D_Wasserhoehe_Wasseranstieg([1:151],[226:367]);
D_HQ10000_WA= PP_D_Wasserhoehe_Wasseranstieg([1:151],[368:509]);
%Maximaler Wasseranstieg
for i=1:151
D_HQ10000_MWA (i,1)= max(D_HQ10000_WA(i,[1:142]));
D_HQ5000_MWA (i,1)= max(D_HQ5000_WA(i,[1:142]));
D_HQextrem_MWA (i,1)= max(D_HQextrem_WA(i,[1:142]));
D_BHQ_MWA (i,1)= max(D_BHQ_WA(i,[1:83]));
end
%Maximaler Wasserrückgang
for i=1:151
D_HQ10000_MWR (i,1)= min(D_HQ10000_WA(i,[1:142]));
D_HQ5000_MWR (i,1)= min(D_HQ5000_WA(i,[1:142]));
D_HQextrem_MWR (i,1)= min(D_HQextrem_WA(i,[1:142]));
D_BHQ_MWR (i,1)= min(D_BHQ_WA(i,[1:83]));
end
%% Überflutungsdauer
PP_D_Wasserhoehe(isnan(PP_D_Wasserhoehe))=0;
D_BHQ_x= PP_D_Wasserhoehe([1:151],[1:83]);
D_HQextrem_x= PP_D_Wasserhoehe([1:151],[84:225]);
D_HQ5000_x= PP_D_Wasserhoehe([1:151],[226:367]);
D_HQ10000_x= PP_D_Wasserhoehe([1:151],[368:509]);
for i=1:151
D_HQ10000_FD (i,1)= nnz(D_HQ10000_x(i,[1:142]));
D_HQ5000_FD (i,1)= nnz(D_HQ5000_x(i,[1:142]));
D_HQextrem_FD (i,1)= nnz(D_HQextrem_x(i,[1:142]));
D_BHQ_FD (i,1)= nnz(D_BHQ_x(i,[1:83]));
end
% Create separate tables for BHQ, HQextrem, HQ5000, and HQ10000
BHQ_table = table(PP_D.OID_, PP_D.FKM, PP_D.Lage, PP_D.X, PP_D.Y, PP_D.z, D_BHQ_MWH, D_BHQ_MWA, D_BHQ_MWR, D_BHQ_FD);
BHQ_table.Properties.VariableNames = {'OID', 'FKM', 'Lage', 'x', 'y', 'z', 'Maximalewasserhöhe', 'Maximaler Wasseranstieg', 'Maximaler Wasserrückgang', 'Maximale Überflutungsdauer'};
HQextrem_table = table(PP_D.OID_, PP_D.FKM, PP_D.Lage, PP_D.X, PP_D.Y, PP_D.z, D_HQextrem_MWH, D_HQextrem_MWA, D_HQextrem_MWR, D_HQextrem_FD);
HQextrem_table.Properties.VariableNames = {'OID', 'FKM', 'Lage', 'x', 'y', 'z', 'Maximalewasserhöhe', 'Maximaler Wasseranstieg', 'Maximaler Wasserrückgang', 'Maximale Überflutungsdauer'};
HQ5000_table = table(PP_D.OID_, PP_D.FKM, PP_D.Lage, PP_D.X, PP_D.Y, PP_D.z, D_HQ5000_MWH, D_HQ5000_MWA, D_HQ5000_MWR, D_HQ5000_FD);
HQ5000_table.Properties.VariableNames = {'OID', 'FKM', 'Lage', 'x', 'y', 'z', 'Maximalewasserhöhe', 'Maximaler Wasseranstieg', 'Maximaler Wasserrückgang', 'Maximale Überflutungsdauer'};
HQ10000_table = table(PP_D.OID_, PP_D.FKM, PP_D.Lage, PP_D.X, PP_D.Y, PP_D.z, D_HQ10000_MWH, D_HQ10000_MWA, D_HQ10000_MWR, D_HQ10000_FD);
HQ10000_table.Properties.VariableNames = {'OID', 'FKM', 'Lage', 'x', 'y', 'z', 'Maximalewasserhöhe', 'Maximaler Wasseranstieg', 'Maximaler Wasserrückgang', 'Maximale Überflutungsdauer'};
for i = 1:83
columnName = sprintf('WH Time %d', i-1);
BHQ_table.(columnName) = D_BHQ_WH(:, i);
end
for i = 1:83
columnName2 = sprintf('WA Time %d', i-1);
BHQ_table.(columnName2) = D_BHQ_WA(:, i);
end
for i = 1:142
columnName = sprintf('WH Time %d', i-1);
HQextrem_table.(columnName) = D_HQextrem_WH(:, i);
HQ5000_table.(columnName) = D_HQ5000_WH(:, i);
HQ10000_table.(columnName) = D_HQ10000_WH(:, i);
end
for i = 1:142
columnName2 = sprintf('WA Time %d', i-1);
HQextrem_table.(columnName2) = D_HQextrem_WA(:, i);
HQ5000_table.(columnName2) = D_HQ5000_WA(:, i);
HQ10000_table.(columnName2) = D_HQ10000_WA(:, i);
end
You can refer to the following documentation to know more about the functions used:
Best Regards,
Abhishek Chakram

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by