MATLAB Answers

How to stock a vector in a vector

2 views (last 30 days)
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 Comments

Geoff Hayes
Geoff Hayes on 27 Mar 2020
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.
Maxime Chapellier
Maxime Chapellier on 27 Mar 2020
Thanks for your answer. Yes it is correct, in fact I would like my X a 3x1000 matrix or a 1000x3 matrix. I try to configure my X before with a zeros(3,1000) but it doesn't solve the problem

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 27 Mar 2020
Edited: Geoff Hayes on 27 Mar 2020
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,:) = ...

  1 Comment

Maxime Chapellier
Maxime Chapellier on 27 Mar 2020
It works !!!
Thank you so much :D

Sign in to comment.

More Answers (0)