Dot indexing is not supported for variables of this type

6 views (last 30 days)
I am not able to understand why this error occurs. Could any one please correct me here. [Kindly look for indicated line where error occured].
age_ranges = [20 30;31 40;41 50;51 60;61 70]; % Modify as needed
age_labels = {'20-30 years','31-40 years','41-50 years','51-60 years','61-70 years'}; % Labels for age ranges
% Create a cell array to store subsets of data based on age ranges
age_groups = cell(size(age_ranges, 1), 1);
% Separate data based on age ranges
for i = 1:size(age_ranges, 1)
% Create logical index for this age range
age_min = age_ranges(i, 1);
age_max = age_ranges(i, 2);
age_idx = data_all_MDV0.AGE >= age_min & data_all_MDV0.AGE <= age_max;
end
% Create subplots for each age group
num_groups = length(age_groups);
figure(3);
for i = 1:num_groups
% Get the subset for this age range
age_data = age_groups{i};
% Number of unique time points
unique_times = unique(age_data.TIME); % !!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!!!!
% Initialize arrays to store mean and 95th percentile
med_values = zeros(size(unique_times));
percentile_2_5 = zeros(size(unique_times));
percentile_97_5=zeros(size(unique_times));
% Loop over each time point to calculate median and 95th percentile
for j = 1:length(unique_times)
current_time = unique_times(j);
% Get all values for the current time point
current_values = age_data.DV(age_data.TIME == current_time);
% Calculate median
med_values(j) = median(current_values);
% Calculate 2.5th percentile
percentile_2_5(j) = prctile(current_values, 2.5);
% Calculate 97.5th percentile
percentile_97_5(j) = prctile(current_values, 97.5);
end
end
  2 Comments
Torsten
Torsten on 9 May 2024
Edited: Torsten on 9 May 2024
Where do you define age_data.TIME ?
age_ranges = [20 30;31 40;41 50;51 60;61 70]; % Modify as needed
age_groups = cell(size(age_ranges, 1), 1);
age_data = age_groups{1};
% Number of unique time points
unique_times = unique(age_data.TIME);
Dot indexing is not supported for variables of this type.
Stephen23
Stephen23 on 9 May 2024
age_groups = cell(size(age_ranges, 1), 1);
..
age_data = age_groups{i};
AGE_DATA is an empty double (the default array in a cell). Why do you expect an empty double to have any fields?

Sign in to comment.

Accepted Answer

Shivani
Shivani on 14 May 2024
Hi @Vijith,
Since all the data files are not shared, I will not be able to determine the exact solution to this issue. However, based on the code snippet shared ‘age_datais a 0x0 empty double array. Since this is essentially a double array it does not contain any labelled 'TIME’ fields. The dot notation you are currently using to access the ‘TIME’ field is used to access columns or fields that are labelled.
You can refer to the following MATLAB documentation link for more details: https://www.mathworks.com/help/stateflow/ug/identify-data-using-dot-notation.html
To access data in the array you will need to index into the specified row and column to retrieve desired data. Please note that the ‘age_data’ is an empty array and therefore you will need to initialise it with data before indexing into it. Once initialized, you can access the required data as shown below:
required_data = age_data(2); %will retrieve the value in the second position of the array
To obtain all the unique values in the array ‘age_data’ you can perform the following action after populating the array with relevant data:
unique_times = unique(age_data);
Kindly refer to this MATLAB documentation link for more details regarding this: https://www.mathworks.com/help/matlabmobile/ug/accessing-array-elements.html
Hope this helps!

More Answers (0)

Categories

Find more on Categorical Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!