How to create a vector with vaules based on a if statement
Mostra commenti meno recenti
I have a task where I need to calculate the surface resistivity of a foundation pile.
The surface resistivity differs based on soil type: clay or sand. For my task I have 4 soil layers where the first two are clay and the two last are sand.
To set up the layer type I've created a vector as follows:
L = [1;1;2;2]; % Layer type: 1=clay | 2=sand
The surface resistivity in a layer is calculated as follows:
If the layer type is clay:
Rs = alpha.*cu.*As % Where alpha is a scalar and cu, As are a 4x1 vector with layer properties
If the layer type is sand:
Rs = Nm.*qs.*As % Where Nm is a scalar and qs, As are a 4x1 vector with layer properties
I could then calculate each layer separately, but to make my script more convenient I'd like to use the two above formulas to calculate Rs as a 4x1 vector showing the surface resistivity in each layer. Here so that the two first values of Rs is calculated using the first formula for clay and the 2 last values using the second formula for sand.
I'm pretty new to matlab, so my skills are fairly basic. So far I've tried something like this,
if L==1;
Rs=alpha.*cu.*As
elseif L==2
Rs=qs.*Nm.*As
end
But this doesn't seems to work and doesn't actually give any output for Rs nor any error.
Edit: The result I'm expecting and trying to achieve is as follow
alpha = 0.4;
Nm = 0.6;
qs = [25;75;125;175];
As = [5;5;5;5]:
cu = [100;100;0;0];
Rs = [200;200;375;525]
Hope it's clear for what I'm trying to do.
Risposta accettata
Più risposte (1)
Walter Roberson
il 23 Nov 2017
0 voti
Categorie
Scopri di più su Historical Contests in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!