MATLAB Answers

If clause – if column blank than

1 view (last 30 days)
Lui Sa
Lui Sa on 19 Nov 2020
Edited: Star Strider on 19 Nov 2020
Hello,
I am encountering a problem with a script I am currently working on. The idea is that any row of a column named "Anxiety_RESP" that does not contain a value ([]) should be replaced with the corresponding value found in a column named "blackscreen_RESP".
So far, I wrote the following code:
for k=1:height (data_pp)
if data_pp.Anxiety_RESP == [];
data_pp.Anxiety_RESP = data_pp.blackscreen_RESP;
else data_pp.Anxiety_RESP = data_pp.Anxiety_RESP;
end
However, the code does not work and the following error is displayed:
Error using ==
Matrix dimensions must agree.
Error in CorrectScript (line 41)
if data_pp.Anxiety_RESP == [];
Thanks a lot!

  0 Comments

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 19 Nov 2020
Try this instead:
if isempty(data_pp.Anxiety_RESP)
.

  2 Comments

Lui Sa
Lui Sa on 19 Nov 2020
Sadly, this does't work either. There are no more error messages, however, the excel file does not display the data_pp.blackscreen_RESP data for the data_pp.Anxiety_RESP.
Star Strider
Star Strider on 19 Nov 2020
I have no idea what the context of this code snippet is, so I cannot provide further help without it.
EDIT — (19 Nov 2020 at 22:17)
Another option:
if all(isempty(data_pp.Anxiety_RESP))
EDIT — (19 Nov 2020 at 22:49)
Still another option (while I am guessing what the data are):
Lidx = isempty(data_pp.Anxiety_RESP)
data_pp.Anxiety_RESP(Lidx) = data_pp.blackscreen_RESP(Lidx)
data_pp.Anxiety_RESP(~Lidx) = data_pp.Anxiety_RESP(~Lidx)
.

Sign in to comment.


VBBV
VBBV on 19 Nov 2020
%f true
if isempty(data_pp.Anxiety_RESP{k})
data_pp.Anxiety_RESP{k} = data_pp.blackscreen_RESP{k};
else
data_pp.Anxiety_RESP{k} = data_pp.Anxiety_RESP{k}
end
Use for loop index to check

  0 Comments

Sign in to comment.

Tags

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by