Display all rows between two ranges
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Cristian Martin
el 3 de Jun. de 2022
Editada: Cristian Martin
el 3 de Jun. de 2022
Hi,
I have to display in a table only the rows in range inputs by the user:
X = readtable('BD\prices.xlsx');
item = get(handles.edit9,'String');%get the number from user
item1 = get(handles.edit10,'String');%get the number from user
V = strcmp(X.data, item);% here its working
V1 = strcmp(X.data1, item1); % here its working
C=X(V:iV1,:); % HERE i dont know how to make the line
disp(C);
data = table2cell(C);
set(handles.uitable1, 'Data', data);
C=X(V:V1,:); % HERE i dont know how to make the line
Thanks!
1 comentario
dpb
el 3 de Jun. de 2022
Don't re-edit the Q? to remove one issue to replace it with another -- now the answer to the original Q? I gave has no bearing on what you've left.
Restore the original content as it was.
The answer above is same thing as I noted in the previous -- the result of inrange is a logical array -- you've displayed that array which will be 0/1 being logical. It appears there's no data that satisfies -- and converting to a cell is the wrong thing to do -- instead convert the first column (why would you name the date colum "Data" instead of "Date"???) to datetime and then test it directly.
As the previous answer showed, then you need to use that logical vector to address the data or convert it to actual indices.
Respuesta aceptada
dpb
el 3 de Jun. de 2022
Editada: dpb
el 3 de Jun. de 2022
You're on the right (no "w" in this type of "right" in English) track -- just use the locations you found as indices -- excepting strcmp returns a logical vector that is only true for the found locations. Apparently you're looking for things that have only one occurrence in the field; if it were possible to have more than one match the following won't work as intended
iV0=find(strcmp(X.data, item)); % get the matching row index
iV1=find(strcmp(X.data1, item1);
C=X(iV0:iV1,:); % select that section of the table
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!