How do I assign start and stop indices for small segments of a large vector to a struct (vector for each file)?

1 view (last 30 days)
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

Answers (2)

Tim leonard
Tim leonard on 12 Mar 2014
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.

Beverly
Beverly on 13 Mar 2014
As it turns out, using curly brackets around {n} and {m} allowed my code to work. I am somewhat new to MatLAB (actually looking for tutor) and realize my programming techniques are not eloquent, but for now, functional works!
Thanks for you input, I'm sure I will be using it down the road!

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!