Display all rows between two ranges

4 views (last 30 days)
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 Comment
dpb
dpb on 3 Jun 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.

Sign in to comment.

Accepted Answer

dpb
dpb on 3 Jun 2022
Edited: dpb on 3 Jun 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

More Answers (1)

Cristian Martin
Cristian Martin on 3 Jun 2022
I'm sorry, I just thought of another option and because no one had answered yet I re-edited, but it happened that at that moment you gave an answer. Once again, I'm sorry about the incident.

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!