Please help: ' Dimensions of arrays being concatenated are not consistent'

1 visualización (últimos 30 días)
Hi all,
I am trying to extract variable name 'average pressure(kpA)' and its each respective numeric value from the total lenght of the attached data and structure it in a table.
When I run the code (below and attached) I get the following error:
Error using vertcat. Dimensions of arrays being concatenated are not consistent.
It spits out the table (t) but with only the first 15 values that I am interested in . Each time when I run the loop manually, it spits out 15 more.
I cannot find the solution how to fix it. Could you please help?
Many thanks
The code
d = load('Data.mat');
n = size(d.data_raw2, 1);
%% Find the left heel keyword
idx_lheel_start = find(strcmp(d.data_raw2(:, 2), '"Left Heel"'));
idx_lheel_end = find(strcmp(d.data_raw2(:, 2), '"Right Heel"'));
t = table();
for i=1:length(idx_lheel_start)
idx = find(strcmp(d.data_raw2(idx_lheel_start(i):idx_lheel_end(i), 1), 'Average Pressure (kPa)'));
a.AVR_PRESSURE = d.data_raw2{idx_lheel_start(i)-1+idx, 2};
t = [t; struct2table(a)];
end
  1 comentario
Yazan
Yazan el 14 de Ag. de 2021
That's an extremely inefficient way to extract the average pressure(kpA) values in a table! Why don't you just do it directly through logical indexing without looping?

Iniciar sesión para comentar.

Respuesta aceptada

Yazan
Yazan el 14 de Ag. de 2021
clc, clear
d = load('Data.mat');
idx_lheel_start = find(strcmp(d.data_raw2(:, 2), '"Left Heel"'));
idx_lheel_end = find(strcmp(d.data_raw2(:, 2), '"Right Heel"'));
% indices between idx_lheel_start and idx_lheel_end
idx = arrayfun(@(idxStart, idxEnd) idxStart:idxEnd, idx_lheel_start, idx_lheel_end,...
'UniformOutput', false);
% corresponding Average Pressure
avgP = cellfun(@(idxx) d.data_raw2(idxx(strcmp(d.data_raw2(idxx, 1), ...
'Average Pressure (kPa)')), 2), idx);
% save in table
T = table(str2double(avgP), 'VariableNames', {'Average Pressure (kPa)'});

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by