Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Store the results of for loop.

1 回表示 (過去 30 日間)
Devansh Patel
Devansh Patel 2019 年 3 月 26 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
TimeBegin = input('Enter the starting date in yyyy-mm-dd - ','s');
TimeEnd = input('Enter the ending date in yyyy-mm-dd - ','s');
%For adding specific fault ID
Channels = input('Enter the Channel IDs - ','s');
% Function for getting the data from the database
GetMeasurement_Enum('ask',1,1,'2016-01-01','2018-12-01','167450',1,'',0,'',1e8)
%Input the Fault Code
n = 4796
y = 1:4796
y1 = transpose(y);
date = cell(n, 1) ;
h1 = cell(n,1)
h2 = cell(n,1)
for Faultcode=1:n
pattern = [Faultcode, 0];
a = transpose(Value);
idx = strfind(a, [Faultcode,0]);
result1 = reshape([idx; idx + length(pattern) - 1], 1, []);
req1 = TimeUTC(result1);
timestamp = req1(1:2:end);
date{Faultcode}=timestamp;
% Extract the timestamps of only fault codes where neccessary and add the
% difference
x1=req1;
h1{Faultcode}=(x1(2:2:end) - x1(1:2:end)) * 24 * 60;
sum1 = sum(h1{Faultcode});
%Find the second pattern of the fault code
idy = strfind(a, [Faultcode,Faultcode]);
result2 = reshape([idy; idy + length(pattern) - 1], 1, []);
req2 = TimeUTC(result2);
x2=req2;
h2{Faultcode}=(x2(2:2:end) - x2(1:2:end)) * 24 * 60;
sum2 = sum(h2{Faultcode});
%Add the duration for both patterns
%Fault_Duration{Faultcode} = sum(h1{Faultcode},h2{Faultcode});
end
%%
T1 = table(date,h1,y1)
T2 = table(date,h2,y1)
X=all(cellfun(@isempty,T1{:,2}),2)
T1(X,:)=[]
Z=all(cellfun(@isempty,T2{:,2}),2)
T2(Z,:)=[]
I am trying to get the duration and timestamp for each faultcode from 1 to 4796. A single faultcode can have multiple timestamps and hence multiple durations. but instead of linear columns I am getting 51*1 double for example for fault 338. So there can we two ways to solve it. From the above table how can I extract data from all these cells arrays and have only 3 columns (date,h1,y1) and only values in it (NO CELL ARRAYS). Another way is how can I directly store the results from for loop without creating cell arrays? Please help.
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 3 月 26 日
Consider for example row 12 of the table, where there appears to be a vector of length 2 for date, and a vector of length 2 for h1, and a scalar for y1. What would be your desired output for that row? Two rows, like [T1{12,1}(1), T1{12,2}(1), T1{12,3}; T1{12,1}(2), T1{12,2}(2), T1{12,3}] ?

回答 (0 件)

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by