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

조회 수: 2 (최근 30일)
Amil Ali
Amil Ali 2023년 5월 1일
편집: Jon 2023년 5월 1일
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

채택된 답변

Jon
Jon 2023년 5월 1일
편집: Jon 2023년 5월 1일
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
Stephen23
Stephen23 2023년 5월 1일
I guess you intended:
nKeep = min(numel(DAPeaks_in),numel(DAPeaks_out));
% ^^^^^^ ^
Jon
Jon 2023년 5월 1일
편집: Jon 2023년 5월 1일
Yes, good catch, thanks! Usually I run my examples to test them for syntax and other errors. I should have done that here too.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2023년 5월 1일
편집: KALYAN ACHARJYA 2023년 5월 1일
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.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by