How do I assign start and stop indices for small segments of a large vector to a struct (vector for each file)?
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to sort a vector (voltage) into separate discharge cycles by finding the start and stop indices through logic with the 'state' and 'ES code' of an output file for all cycles in the 6704 x 1 vector. So the desired return is a struct where discharge(2).End gives me all the end points of discharge cycles from file 2. I am somewhat new to Matlab, help would be greatly appreciated! allData(iiFile).State(n) works, though I am not sure the logic is or that I am assigning discharge.Start and discharge.End correctly.
for n = 1:numel(allData(iiFile).Volt) %.Struct is optional as all are same length for each file
if num2str(allData(iiFile).State(n)) == 'D' & allData(iiFile).ES(n)==0
m=1
discharge{iiFile}.Start(m)=n
disp(discharge(iiFile).Start)
m=m+1
end
if num2str(allData(iiFile).State(n)) == 'D' & allData(iiFIle).ES(n)==132
m=1
discharge{iiFile}.End(m)=n
m=m+1
end
end
The error I am getting is : Undefined function 'abs' for input arguments of type 'cell'.
Error in num2str (line 65) xmax = double(max(abs(widthCopy(:))));
Error in mainDataExtractor_Bev (line 76) if num2str(allData(iiFile).State(n)) == 'D' & allData(iiFile).ES(n)==0
0 件のコメント
回答 (2 件)
Tim leonard
2014 年 3 月 12 日
Your widthCopy is a cell, bout your treating it as a vector. Without seeing the rest of your code I have to guess. This is what I would do:
endxmax = double(max(abs(widthCopy(:))));
with this:
endmax = double(cellfun(@(x)(max(abs(x))),widthCopy));
which will calculate max(abs()) for each element in the cell array, and return a vector of those values.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!