How to separate Vector in different Lenghts

1 次查看(过去 30 天)
Hello,
i have one Vector CamData(1:128)
and I want to separate it to two different Vectors:
CamDataNEW1 = CamData(10:Value)
CamDataNEW2 = CamData(Value+1:118)
I program for an µC so, but i don't want to allow variable Sized Signals (processing Speed).
So i am searching for a Solution with preallocated Variables.
camDataNew1 = cell(1:128);
camDataNew2 = cell(1:128);
camDataNew1 = arr_CameraDiff(10:n_TrackMiddle);
camDataNew2 = arr_CameraDiff(n_TrackMiddle+1:118);
After this I want to look for Minima in each Part and get the Index.
How can I accomplish this?
Thank you for helping out!
  1 个评论
Walter Roberson
Walter Roberson 2015-11-27
cell(1:128) would try to create a cell array with 128 dimensions, a 1 x 2 x 3 x 4 x 5 x 6 x ... x 128 cell array.
cell arrays are dynamic structures that are effectively variable sized signals, which you do not wish to use.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2015-11-27
Well, unless you fix the value of Value it's going to be a variable-length vector by definition. I don't know where the uC is coming in at; if you have the toolbox you can generate code for such but I'd certainly not use cell arrays for the purpose.
If you have a input buffer of length 128 then just write in Matlab
v1=CamData(1:Value);
v2=CamData(Value+1:end);
If you wish if there's a max for Value less than length(CamData) then you can write
v1=zeros(1:Value);
v2=zeros(1:maxLength);
to preallocate the two arrays. Then you'd write
v1(1:Value)=CamData(1:Value);
v2(1:maxLength-Value)=CamData(Value+1:end);
to assign altho note here you'll have to clear the buffer each time of any extraneous values left over from a previous iteration if Value changes. If, of course, it is fixed then you can make the two buffers identically the correct size. You also, if do the above must treat the "empty" values correctly for whatever is the proper behavior. All in all, it may well be less actual overhead to allocate the proper size instead.
The min/location is trivial with the alternate optional return values.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by