Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

How I can do? Tsol=(G==0)=Tamb

Asked by Liviu

Liviu (view profile)

on 19 Nov 2012
Accepted Answer by Matt J

Matt J (view profile)

G=[1;0;2;3;0];
Tsol=[11; 12; 13;14;15];
Tamb=[10;15;16;16;12]
Tsol(G==0)=Tamb;

if all the variables are only one row it works but when is an array not.

Thanks

4 Comments

Liviu

Liviu (view profile)

on 19 Nov 2012

This are array: G=[1;0;2;3;0]; Tsol=[11; 12; 13;14;15]; Tamb=[10;15;16;16;12]

The final resultant neet to be: Tsol= 11 15 13 14 12 in stead of 11 12 13 14 15 the 12 and 15 are change and comes from Tamb

Image Analyst

Image Analyst (view profile)

on 19 Nov 2012

Those are 1D vectors, not 2D arrays. Matt's solution will work fine on them. I don't know why you said it works with one row - I ran your code and it didn't work (but with Matt's fix it works). How did you get that to work????? In fact I believe Matt's fix should also work for arrays of any dimension since it uses linear indexing.

Liviu

Liviu (view profile)

on 19 Nov 2012

The solution is: Tsol(G==0) = Tamb(G==0);

Liviu

Liviu (view profile)

Products

1 Answer

Answer by Matt J

Matt J (view profile)

on 19 Nov 2012
Accepted answer

No, your example doesn't run and will not generally work for vector input either. However, this might be what you want:

Tsol(G==0) = Tamb(G==0);

1 Comment

Liviu

Liviu (view profile)

on 19 Nov 2012

Perfect

Matt J

Matt J (view profile)

Contact us