display value if it lies between x and y

4 visualizaciones (últimos 30 días)
C.G.
C.G. el 18 de En. de 2021
Comentada: C.G. el 18 de En. de 2021
I have a series of csv files, which I want to input into a for loop, which tells me if any of the numbers in column 5 of the csv are between -0.16 and -0.13.
Currently when I run this i get the error: " Operands to the || and && operators must be convertible to logical scalar values."
Could anybody help me please?
ymax = -0.13;
ymin = -0.16;
for b = 1:length(particledata)
%save all the rows in the 6th column (x-coordinates) of each cell as a new variable x
x{b} = particledata{b}(:,5);
%use the function table2array to turn the format of the data from a table to an array
x_array{b} = table2array(x{b});
%for all the rows in the array, if the x coordinate goes beyond the outlet
%of the rice pile, display 'grain left rice pile'
if (x_array{b}>ymin && x_array{b}<ymax)
disp('grain left rice pile');
end
%sum the total number of grains leaving the rice pile in each cell, and save into a new variable 'grains'
grains{b}=sum(x_array{b}>ymin) && (x_array{b}<ymax)
fprintf('A total of %d grains left the rice pile\n',grains{b});
end

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 18 de En. de 2021
Editada: KALYAN ACHARJYA el 18 de En. de 2021
Try with single "&"
Note "x_array{b}>ymin" or "x_array{b}<ymax" return logical array data. If all the array elements of the array is greater than ymin or vice versa, it generates array with all logical ones, other case array with zeros
The if condition is true ...only if
x_array{b}>ymin retun 1 1 1 1....and
x_array{b}<ymax return 1 1 1 1.....
  1 comentario
C.G.
C.G. el 18 de En. de 2021
I have tried with a single '&' and the error still occurs.
I need the code to identify all the cells that contain a number between -0.16 and -0.13 as i want to save these numbers into a new csv.

Iniciar sesión para comentar.

Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by