The expression to the left of the equals sign is not a valid target for an assignment in an if statement

3 views (last 30 days)
Hello! I was wondering if anyone would be able to help me - quite straight forward but not sure why I cant get my if clause to work as is saying "The expression to the left of the equals sign is not a valid target for an assignment". Any help would be great - please see code with notes below. Thank you
%%there are 18 data files to load and save as Data
for i = 1:18
Data(i) = load(strcat('C:\Users\MATLAB\DATA\subData_', num2str(i),'.mat'))
subDataTablelength(i) = length(Data(i).subData);
end
numOfData = length(Data);
%%I then want to evaluate each element in coloumn 7 of each subData set
for k = 1:numOfData;
for m = 1:subDataTableLength(i);
currentData = Data(k).subData;
subDataRow = Data(k).subData(m,7);
if Data(k).subData(m)= 5; % this is coming out as unbalanced even though Data(k).subData(m) is a single number
difficultyFive(m) = Data(k).subData(m);
else difficultyfive(m) = 0;
end
end
end

Answers (1)

Torsten
Torsten on 28 Sep 2018
Edited: Torsten on 28 Sep 2018
if Data(k).subData(m)== 5
difficultyFive(m) = Data(k).subData(m);
else
difficultyFive(m) = 0;
end

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!