eliminate column for condition

i have 1096x653 double the row is not consistent
i wannt to eliminate column having data below 60 and greater than 80
but my code below show some error
xlsread filename.xlsx
for ans<=60 && ans>=80
ans(:,~any(ans,1))=[]
xlswrite ('medium.xlsx',ans);
end
%the error%
for ans<=60 && ans>=80
Error: Unexpected MATLAB operator.

1 comentario

Guillaume
Guillaume el 18 de Mzo. de 2019
Editada: Guillaume el 18 de Mzo. de 2019
Do not rely on the ans variable. You run the risk that it gets overwritten. Assign the function output to a variable with a meaningful name.
"Error: Unexpected MATLAB operator."
You'll get that a lot if you start inventing your own syntax. Documentation of for.

Respuestas (1)

madhan ravi
madhan ravi el 18 de Mzo. de 2019
Editada: madhan ravi el 18 de Mzo. de 2019
Ans(:, any( (Ans <= 60) | ( Ans >= 80 ),1)) = []
% don’t name a variable ans

2 comentarios

Guillaume
Guillaume el 18 de Mzo. de 2019
He's not named his variable ans, he's using the built-in ans variable that is automaticaly created by matlab when you don't specify any output to a function with one or more outputs (in this case, the xlsread function).
This is of course asking for trouble, since if he calls another function without giving it an output, his ans variable will get overwritten.
The fix is to specify an output variable in the call to xlsread, which means using function syntax instead of command syntax:
data = xlsread('filename.xlsx');
madhan ravi
madhan ravi el 18 de Mzo. de 2019
Very true Guillaume, thank you for the professional description.

La pregunta está cerrada.

Etiquetas

Preguntada:

el 18 de Mzo. de 2019

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by