indexing with cells (need specific value in all the rows of a column
44 次查看(过去 30 天)
显示 更早的评论
I have data populating in a cell as such:
I'm trying to extract data from all of the rows in column 6. When I try:
tx_data{:,6}(3,:)
but I get:
Expected one output from a curly brace or dot indexing expression, but there were 5
results.
I'm trying to plot those 5 results for a graph that will be updated per measurement. Obviously it sees the 5 results that I'm looking for, but I can't seem to actually get that data to pass to my function (something like what's below...TBD):
plot(gui_app.TRPApp.UIAxes, tx_data{:,6}(3,:));
The number of rows in this cell array will be dependent on the test being run. I may need to do something similar while separating data marked at 'v' or 'h', but I'm not quite sure if I'll need that or not.
Any help would be much appreciated!
0 个评论
回答(1 个)
Gaurav Garg
2020-12-28
编辑:Gaurav Garg
2020-12-28
Hi Scott,
While using tx_data{:,6}(3,:), you were expected to get an error. That's because intermediate brace {} indexing produced a comma-separated list, and to perform indexing, it must have produced a single value.
However, there is one other thing you can do -
% Assuming that c is a cell array of size (4,4)
c{1,2} = [2,2,2,2]
c{2,2} = [2,2,2,2]
c{3,2} = [2,2,2,2]
c{4,2} = [2,2,2,2]
[c{[1:4],2}] % This command helps you convert the second column in the cell array to a single-dimensional array.
plot([1:16],[c{[1:4],2}]) % You can use it as a normal 1-D array and plot the values
In your case specifically, you can manipulate this 1-D array to plot only the required values. (tx_data{:,6}(3,:))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!