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)
  
       Show older comments
    
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
1 Comment
  Stephen23
      
      
 on 28 Sep 2018
				This is assignment of a value to a variable:
Data(k).subData(m) = 5
This is a test for equality:
Data(k).subData(m) == 5
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

