Display all rows between two ranges
4 次查看(过去 30 天)
显示 更早的评论
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
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
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
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!