How to stock a vector in a vector
6 ビュー (過去 30 日間)
古いコメントを表示
Maxime Chapellier
2020 年 3 月 27 日
コメント済み: Maxime Chapellier
2020 年 3 月 27 日
Hello everybody !
I'm in trouble with this : I would like to change the value of water_u in my loop and to stock the result in X (a 3 colomns or 3 rows matrice).
It doesn't work... Can someone help me ? :)
Many thanks in advance
clear all
close all
clc
water_density = [0.997]; %[g/cm3]
water_att = [1.64e-1; 6.40e-2; 2.92e-2]; %[cm2/g] @100, 1000, 10000 keV
water_u = water_density.*water_att; %[cm-1]
R = rand(1,1000);
for i=1:3
X = -(log10(1-R)./water_u(i));
end
2 件のコメント
Geoff Hayes
2020 年 3 月 27 日
Maxime - your R is a 1x1000 matrix. Is that correct? It seems that you are using a different value of water_u in your loop (good), but because of the size of R, the X can never be a 3x1 or 1x3 matrix.
採用された回答
Geoff Hayes
2020 年 3 月 27 日
編集済み: Geoff Hayes
2020 年 3 月 27 日
Maxime - try doing
X = zeros(3,1000);
for i=1:3
X(i,:) = -(log10(1-R)./water_u(i));
end
where we use the : to indicate all columns in the ith row of X X(i,:) via
X(i,:) = ...
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!