Replace the elements of a matrix under specific conditions
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Camilo Granda
el 7 de Oct. de 2017
Comentada: Camilo Granda
el 7 de Oct. de 2017
I have an Esi matrix and want to replace it by the following parameters:
- if the values of Esi are greater or equal than f_y/Es replace the values with f_y
- if the values of Esi are lesser or equal than -f_y/Es replace the values with -f_y
- and for the values in between -f_y/Es<Esi<+f_y/Es i want to replace them by: Esi*Es
So long I have this:
fsi=zeros(size(Esi)); fsi(Esi>=f_y/Es)=f_y; fsi(Esi<=-f_y/Es)=-f_y; fsi(-f_y/Es<Esi<f_y/Es)=Esi*Es;
But is not working.
0 comentarios
Respuesta aceptada
Image Analyst
el 7 de Oct. de 2017
You can't do this
-f_y/Es < Esi < f_y/Es
You need to do it in two steps, like (-f_y/Es < Esi) & (Exi < f_y/Es). So try this:
fsi=zeros(size(Esi));
fsi(Esi>=f_y/Es)=f_y;
fsi(Esi<=-f_y/Es)=-f_y;
fsi((-f_y/Es < Esi) & (Exi < f_y/Es)) = Esi * Es;
Or perhaps a little more readable and less cryptic for people reading your code.
fsi = zeros(size(Esi));
indexesToReplace = Esi >= f_y/Es;
fsi(indexesToReplace) = f_y;
indexesToReplace = Esi <= -f_y/Es;
fsi(indexesToReplace) = -f_y;
indexesToReplace = (-f_y/Es < Esi) & (Exi < f_y/Es);
fsi(indexesToReplace) = Esi * Es;
Más respuestas (0)
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!