How i can i Ensure that my 2 vectors have the same size?!

2 views (last 30 days)
I have the following code (below) and want that DAPEAK_IN (1X86) and DAPEAK_OUT (1X63) have the same size i tried using this code
%Calculate daily averages from CleanPeaks, Max Threshold set to 2000, where 2 is values in and 4 is values out
DAPeaks_in = DailyAverageNY(CleanPeaks_in,2,5,100);
DAPeaks_out = DailyAverageNY(CleanPeaks_out,4,5,100);
DAPeaks_in = DAPeaks_in(1:size(DAPeaks_out,1),:); % adjust the size of DAPEAKS_IN to DAPEAKS_OUT and vice versa
DAPeaks_out = DAPeaks_out(1:size(DAPeaks_in,1),:)
however the stil have the same size as before DAPEAK_IN (1X86) and DAPEAK_OUT (1X63) - any suggestion on how to achevie this FYI i have not tried any function for it
best regards - Amil Ali

Accepted Answer

Jon
Jon on 1 May 2023
Edited: Jon on 1 May 2023
If you want DAPEAK_in to have the same dimension as DAPEAK_out then I assume you want both of them to have the same dimesion as the smallest of the two. Otherwise you would somehow have to add values, or just put zeros to lengthen the shorter one. You could do something like this (I have assumed, as in your description that both are row vectors):
%Calculate daily averages from CleanPeaks, Max Threshold set to 2000, where 2 is values in and 4 is values out
DAPeaks_in = DailyAverageNY(CleanPeaks_in,2,5,100);
DAPeaks_out = DailyAverageNY(CleanPeaks_out,4,5,100);
% determine number of elements in the shorter one
nKeep = min(numel(DAPeaks_in),DAPeaks_out);
% adjust the size of DAPEAKS_IN to DAPEAKS_OUT and vice versa
% set them both to the same length
DAPeaks_in = DAPeaks_in(1,1:nKeep);
DAPeaks_out = DAPeaks_out(1:nKeep);
  2 Comments
Stephen23
Stephen23 on 1 May 2023
I guess you intended:
nKeep = min(numel(DAPeaks_in),numel(DAPeaks_out));
% ^^^^^^ ^
Jon
Jon on 1 May 2023
Edited: Jon on 1 May 2023
Yes, good catch, thanks! Usually I run my examples to test them for syntax and other errors. I should have done that here too.

Sign in to comment.

More Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 1 May 2023
Edited: KALYAN ACHARJYA on 1 May 2023
Hope I have understand the question- Here is the example
DAPEAK_IN=randi([1,100],[1,randi(200)]); %Random data
size(DAPEAK_IN)
ans = 1×2
1 65
DAPEAK_OUT=randi([1,100],[1,randi(200)]); %Random data
size(DAPEAK_OUT)
ans = 1×2
1 88
if size(DAPEAK_IN,2)>size(DAPEAK_OUT,2)
DAPEAK_IN=DAPEAK_IN(1:size(DAPEAK_OUT,2));
else
DAPEAK_OUT=DAPEAK_OUT(1:size(DAPEAK_IN,2));
end
size(DAPEAK_IN)
ans = 1×2
1 65
size(DAPEAK_OUT)
ans = 1×2
1 65
The size can also be done with extrapolate, actually representing the data set. Here I have foreced the data in particular range, the remaining will be lost which may be meningful data, please look on that point.

Categories

Find more on Linear Algebra 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!