필터 지우기
필터 지우기

how to get adress position inside vector

조회 수: 1 (최근 30일)
alize beemiel
alize beemiel 2022년 3월 12일
답변: Jan 2022년 3월 12일
hi!
please for some help
i have this vector
i need to some value of eld in a vector gravlo just in right position given in vector adress
but matlab say Subscript indices must either be real positive integers or logicals.
can someone help me how to fix it
gravlo=zeros(1,100);
eld =[ 0
-1.7222
0
7.0000
0
-1.7778
0
6.8889
0
-1.7778
0
7.0000
0
-1.7222
0
7.1111];
adress =[ 0
3
0
2
0
1
31
32
61
62
63
64
65
66
33
34 ];
gravlo(adress)=gravlo(adress)+eld.*20;
  댓글 수: 7
Jan
Jan 2022년 3월 12일
편집: Jan 2022년 3월 12일
A simplified version of your code:
gravlo = zeros(427,1);
for iel=1:5
g = G(:,iel);
m = (g ~= 0);
gravlo(g(m)) = gravlo(g(m)) - eld(m) * 20;
end
Hints: Do not use "clear all" in productive code, because it is a waste of time only.
Use the buttons on top of the field for posting messages to format the code. This improves the readability.
alize beemiel
alize beemiel 2022년 3월 12일
oh !!!
thank you Sir,
its very nice and its work with a simply code
thanks very much Sir,

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

채택된 답변

Jan
Jan 2022년 3월 12일
Copied from my comment as an answer:
gravlo = zeros(427,1);
for iel = 1:5
g = G(:, iel);
m = (g ~= 0);
gravlo(g(m)) = gravlo(g(m)) - eld(m) * 20;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by