Display all rows between two ranges

조회 수: 4 (최근 30일)
Cristian Martin
Cristian Martin 2022년 6월 3일
편집: Cristian Martin 2022년 6월 3일
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
dpb
dpb 2022년 6월 3일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2022년 6월 3일
편집: dpb 2022년 6월 3일
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

추가 답변 (1개)

Cristian Martin
Cristian Martin 2022년 6월 3일
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.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by