Extracting data from cell array: Unable to perform assignment because the indices on the left side are not compatible with the size of the right side

2 visualizaciones (últimos 30 días)
Hi there, I have a 1*365 cell, in which it contains 365 3191*1 cells. I need to extract data (e.g., a GPS station data) from each 3191*1 cell.
By running the code (below), I always get 'Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.' Can anyone offer any suggestions? Thanks in advance.
clear all; clc;
loadf = 1;
files = dir('*.txt');
for i=1:length(files)
F = fullfile(files(i).name);
fid(i)=fopen(files(i).name);
files(i).values=textscan(fid(i), '%s','delimiter',',','HeaderLines',20,'MultipleDelimsAsOne',1);
end
for i = 1:length(files)
for v = 1:numel(files)
val(i) = files(v).values;
end
end
for k = 1:length(val)
WARK(i) = cell2mat(val{1,k}([2952:2963]));
end

Respuestas (1)

Ameer Hamza
Ameer Hamza el 4 de Dic. de 2020
Can you explain in which form do you want the output? The following show how you can extract those values and store them in a cell array
WARK = cell(size(val))
for k = 1:length(val)
WARK{k} = cell2mat(val{1,k}(2952:2963));
end
  5 comentarios
Ameer Hamza
Ameer Hamza el 4 de Dic. de 2020
Can you attach these variables in a .mat file. It will make it easier to suggest a solution.
Vicky Liu
Vicky Liu el 4 de Dic. de 2020
Hi Ameer
Please find the attachments. I only attach 2 days data (in .mat files and .txt files) as example. Actually, those data are TRO file extension files, which I downloaded from Index of /CODE/2019/ (unibe.ch). I converted those .TRO files to .txt files in Matlab by:
files=dir('*.TRO')
for i=1:length(files)
filename=files(i).name;
[pathstr, name, ext] = fileparts(filename);
copyfile(filename, fullfile(pathstr, [name '.txt']))
end
Then, I use the code listed below (which you have already seen in the previous conversation) to extract WARK station data.
clear all; clc;
loadf = 1;
files = dir('*.txt');
for i=1:length(files)
F = fullfile(files(i).name);
fid(i)=fopen(files(i).name);
files(i).values=textscan(fid(i), '%s','delimiter',',','HeaderLines',20,'MultipleDelimsAsOne',1);
end
val = cell(size(files));
for i = 1:length(files)
for v = 1:numel(files)
val{i} = files(i).values;
end
end
subval = cell(size(val));
for k = 1:length(val)
subval{k} = val{k,1}{1,1};
end
% WARK = cell(size(subval));
for a = 1:length(subval)
WARK = cell2mat(subval{a,1}(3008:3019)); %This is not correct....
end
Thanks in advance.

Iniciar sesión para comentar.

Categorías

Más información sobre Programming 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