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!