Extracting a double array from within a struct
이전 댓글 표시
I have a structure of 1x297 with 13 fields. One of those fields is called contains a double array within each cell of the structure (297 times) and that varies in row length (between 300 and 1000), but has 18 columns. This is where it gets complicated...
I want to extract the entire row from each double array, within the struct, where the value in the second column is >= 4 and <= 5.
So in the end I will have an 18x297 array.
Apologies if this isn't very clear. Thank you!
채택된 답변
추가 답변 (1개)
Image Analyst
2024년 3월 18일
Structures have "fields" not "cells".
"One of those fields is called contains..." <== is called WHAT??? You left out the name of the field.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Assuming your structure is called s, and your unnamed field is called data, you can do
data = s.data;
% Get a logical vector of rows that meet the extraction criteria.
rowsToExtract = data(:, 2) >= 4 & data(:, 2) <= 5;
result = data(rowsToExtract, :); % An Nx18 matrix where N can be as much as 297.
% In the end I want an 18x297 array (18 rows, not columns)
% so we must transpose to get 18 rows, not a variable number of rows.
result = result.'; % Transpose
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
