extract small vector from large vector
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
b=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
a=zeros(3,1);
c=([a;b]);
d=(c(1,1):c(6,1));
e=(c(4,1):c(9,1));
please suggest me the way how can i write the code for vector d and e.
i want d vector as; d= [0;0;0;1;2;3] and
vector e as ; e=[1;2;3;4;5;6]
채택된 답변
Voss
2022년 4월 8일
b = [1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
a = zeros(3,1);
c = [a; b]
c = 18×1
0
0
0
1
2
3
4
5
6
7
d = c(1:6,1) % ",1" not necessary since c only has one column
d = 6×1
0
0
0
1
2
3
e = c(4:9) % ",1" omitted
e = 6×1
1
2
3
4
5
6
댓글 수: 8
Thanks Sir,
Voss
2022년 4월 8일
You're welcome!
sir, just tell me is it correct? if wrong please correct me.
utdelt=([1;2;3;4;5;6;7;8;9;10;11;12;13;14;15]);
nodof=3;
for i=1
for n=1:1:5
if n==1
Utdelt=([zeros(nodof,1); (utdelt(1:nodof,i))]);
eval(['Utdelt',num2str(n),'=[zeros(nodof,1); (utdelt(1:nodof,i))]']);
else
Utdelt=utdelt([(1+(n-2)*nodof):(6+(n-2)*nodof),(i)]);
eval(['Utdelt',num2str(n),'=[utdelt([(1+(n-2)*nodof):(6+(n-2)*nodof,(i)])]']);
end
end
I can't say whether it's correct since I don't know what it's supposed to do, but I would make Utdelt a matrix:
utdelt=([1;2;3;4;5;6;7;8;9;10;11;12;13;14;15]);
nodof=3;
Utdelt = zeros(6,5);
for i=1
for n=1:1:5
if n==1
Utdelt(:,n) = [zeros(nodof,1); utdelt(1:nodof,i)];
else
Utdelt(:,n) = utdelt( 1+(n-2)*nodof : 6+(n-2)*nodof , i );
end
end
end
Utdelt
Utdelt = 6×5
0 1 4 7 10
0 2 5 8 11
0 3 6 9 12
1 4 7 10 13
2 5 8 11 14
3 6 9 12 15
sir i want to extract Utdelt as a column vector of 6X1.
But you calculate Utdelt in a loop that iterates 5 times.
If you want each Utdelt as a 6x1 column vector then how you had it was basically fine. Here is your code again, except without the eval statements, without all the unnecessary parentheses, fixing the indentation, and adding a missing end at the end.
utdelt=([1;2;3;4;5;6;7;8;9;10;11;12;13;14;15]);
nodof=3;
for i=1
for n=1:1:5
if n==1
Utdelt = [zeros(nodof,1); utdelt(1:nodof,i)];
else
Utdelt = utdelt( 1+(n-2)*nodof : 6+(n-2)*nodof , i );
end
Utdelt
% presumably, you would do something with Utdelt at this point
end
end
Utdelt = 6×1
0
0
0
1
2
3
Utdelt = 6×1
1
2
3
4
5
6
Utdelt = 6×1
4
5
6
7
8
9
Utdelt = 6×1
7
8
9
10
11
12
Utdelt = 6×1
10
11
12
13
14
15
thank you sir, in this loop i am calculating the f_s but when i am seeing the result the output is comin wrong.
utdelt=([1;2;3;4;5;6;7;8;9;10;11;12;13;14;15]);
Ktts=rand(6,6);
nodof=3;
for i=1
for n=1:1:5
if n==1
Utdelt = [zeros(nodof,1); utdelt(1:nodof,i)];
else
Utdelt = utdelt( 1+(n-2)*nodof : 6+(n-2)*nodof , i );
end
Utdelt
% presumably, you would do something with Utdelt at this point
end
f_s=Ktts*Utdelt;
end
Voss
2022년 4월 15일
That uses the value of Utdelt that was calculated for n=5. Previously calculated Utdelt values, i.e., for n=1 through n=4, are not used. Maybe that's what's wrong.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
