From: Arie Driga on
Hi all,

I have two matrices, each with size of 5x11. I would like to compare each element in each matrix with a value.


I use if for this purpose:

if (Xh_channel <= 0.24 && Xt_channel >= 0.15)
%pass = 1;
for i = 1:size(x_var,1)
Nu_mean=interp1(linspace(1,0.166667,size(y_var_nu_ch_1,1)),z_var_nu_ch_fine_1(i,:), x_var(i,:));
end
end;

but.. I have this error message:

??? Operands to the || and && operators must be convertible to logical scalar values.

Error in ==> channel_heat_transfer at 81
if ((Xh_channel <= 0.024) && (Xt_channel >= 0.015))

I hope my explanation is clear enough. Looking forward for some assistances here.

Thank you.
From: Sean on
"Arie Driga" <a_driga(a)yahoo.com> wrote in message
> ??? Operands to the || and && operators must be convertible to logical scalar values.
>
> Error in ==> channel_heat_transfer at 81
> if ((Xh_channel <= 0.024) && (Xt_channel >= 0.015))

Without looking at anything else you're trying to do a scalar operation on a vector or matrix. Use a single '&' or '|' when doing this.

Good luck!
From: Steven Lord on

"Arie Driga" <a_driga(a)yahoo.com> wrote in message
news:hs8r51$kjp$1(a)fred.mathworks.com...
> Hi all,
>
> I have two matrices, each with size of 5x11. I would like to compare each
> element in each matrix with a value.
>
>
> I use if for this purpose:
>
> if (Xh_channel <= 0.24 && Xt_channel >= 0.15)
> %pass = 1;
> for i = 1:size(x_var,1)
> Nu_mean=interp1(linspace(1,0.166667,size(y_var_nu_ch_1,1)),z_var_nu_ch_fine_1(i,:),
> x_var(i,:));
> end
> end;
>
> but.. I have this error message:
>
> ??? Operands to the || and && operators must be convertible to logical
> scalar values.
>
> Error in ==> channel_heat_transfer at 81
> if ((Xh_channel <= 0.024) && (Xt_channel >= 0.015))
>
> I hope my explanation is clear enough. Looking forward for some
> assistances here.

As the message indicates, && and || are only intended to be used for
_scalar_ inputs. Since your Xh_channel is a matrix, you cannot use && for
this purpose.

However, simply replacing && by & as Sean suggested may not be sufficient in
this case. That would only execute the loop body if ALL of the elements of
Xh_channel were between 0.15 and 0.24 inclusive, which is not what I believe
you want to do. See the remark "Nonscalar expressions" on the reference
page for IF for an explanation.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/if.html

If you want to operate only on those elements of Xh_channel that are in that
interval, use logical indexing.

indicesOfElementsInInterval = (Xh_channel >= 0.15 & Xh_channel <= 0.24);
elementsInInterval = Xh_channel(indicesOfElementsInInterval);

Now operate on the elements of elementsInInterval.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Arie Driga on

> As the message indicates, && and || are only intended to be used for
> _scalar_ inputs. Since your Xh_channel is a matrix, you cannot use && for
> this purpose.
>
> However, simply replacing && by & as Sean suggested may not be sufficient in
> this case. That would only execute the loop body if ALL of the elements of
> Xh_channel were between 0.15 and 0.24 inclusive, which is not what I believe
> you want to do. See the remark "Nonscalar expressions" on the reference
> page for IF for an explanation.
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/if.html
>
> If you want to operate only on those elements of Xh_channel that are in that
> interval, use logical indexing.
>
> indicesOfElementsInInterval = (Xh_channel >= 0.15 & Xh_channel <= 0.24);
> elementsInInterval = Xh_channel(indicesOfElementsInInterval);
>
> Now operate on the elements of elementsInInterval.
>
> --
> Steve Lord
> slord(a)mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

I tried using your syntax

> indicesOfElementsInInterval = (Xt_channel >= 0.15 & Xh_channel <= 0.24);
> elementsInInterval = Xh_channel(indicesOfElementsInInterval);

Thank you! I think it works now..