how to get adress position inside vector
古いコメントを表示
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 件のコメント
Arif Hoq
2022 年 3 月 12 日
can you show us your expected result ?
i need to some value of eld in a vector gravlo just in right position given in vector adress
which value of 'eld' do you want in 'gravlo' vector?
alize beemiel
2022 年 3 月 12 日
Torsten
2022 年 3 月 12 日
At least, eld and G should have the same number of rows.
This is not true in your case.
Even if they had the same number of rows, if you remove indices from g as you do, the line
gravlo(g(g~=0))=gravlo(g(g~=0))-eld*20;
will no longer work.
Further, "gravlo" must be a column, not a row vector.
Arif Hoq
2022 年 3 月 12 日
You have these array (gravlo,eld,address,G). still i am not clear about your expectation.can you show some result ? like 4/5 rows of your expected result
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 ];
G=[3 66 156 246 336
0 63 153 243 333
2 64 154 244 334
0 61 151 241 331
1 62 152 242 332
31 121 211 301 391
32 122 212 302 392
61 151 241 331 421
62 152 242 332 422
63 153 243 333 423
64 154 244 334 424
65 155 245 335 425
66 156 246 336 426
33 123 213 303 393
34 124 214 304 394];
alize beemiel
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
2022 年 3 月 12 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!