필터 지우기
필터 지우기

how to make multiple vectors of different lengths equal

조회 수: 1 (최근 30일)
tony karamp
tony karamp 2013년 4월 16일
hello all,
I have five vector with different lengths and I want to find the vector with the largest length, then fill the rest of the vectors with zeros, until they are of equal length as the largest one.
vec1 = [48 158]
vec2 = [658 71 47 82]
vec3 = [6 34 73 42 542 3]
vec4 = [5]
vec5 = [85 68 2 6]
I want to find the largest vector and then fill the rest of the vector with zeros so that I have that
vec1 = [48 158 0 0 0 0]
vec2 = [658 71 47 82 0 0]
vec3 = [6 34 73 42 542 3]
vec4 = [5 0 0 0 0 0]
vec5 = [85 68 2 6 0 0]
Note that the length of the vectors is not known to me, I just want to make them equal.
Any advice? Thanks in advance!

채택된 답변

Image Analyst
Image Analyst 2013년 4월 16일
vec1 = [48 158]
vec2 = [658 71 47 82]
vec3 = [6 34 73 42 542 3]
vec4 = [5]
vec5 = [85 68 2 6]
maxLength = max([length(vec1), length(vec2), length(vec3), length(vec4), length(vec5)])
vec1(length(vec1)+1:maxLength) = 0
vec2(length(vec2)+1:maxLength) = 0
vec3(length(vec3)+1:maxLength) = 0
vec4(length(vec4)+1:maxLength) = 0
vec5(length(vec5)+1:maxLength) = 0

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by