Unexpected MATLAB expression? (trying to create a function) -


load('matrix.mat'); userinput = input('input value 1-5') dayreport = sum(matrix(:,end 2);==userinput) 

i trying retrieve number of rows in column 2 of loaded matrix corresponds userinput. however, when try run code, says there error in third line (simply, "unexpected matlab expression"). ideas why is?


edit: found solution, turns out don't need "end" or semicolon within sum function.

load('matrix.mat'); userinput = input('input value 1-5') dayreport = sum(matrix(:,2)==userinput) 

remove semi-colon , end statement in last line of code. guess want access second column of matrix, , it's matrix(:,2).

also, suspect copied , pasted code somewhere. that's bad programming practice because copied code may work in situation, if try , bring current context, may different you're doing , can result in errors.

see discussion on programmers stack exchange on why should avoid together: https://softwareengineering.stackexchange.com/questions/87696/is-copy-paste-programming-bad


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -