Azzera filtri
Azzera filtri

Why can't I concatenate?

1 visualizzazione (ultimi 30 giorni)
Rebecca Jones
Rebecca Jones il 1 Ott 2019
Commentato: Guillaume il 1 Ott 2019
Hello! I have set up the following code and am trying to add a row onto table P each time I loop. I keep getting the following error:
"Error using Codey (line 104)
Could not concatenate the table variable 'Title' using VERTCAT.
Caused by:
Error using tabular/vertcat (line 164)
All tables in the bracketed expression must have the same number of variables."
Pnew and P both have the same variable names and types. I can't see what to do!
files = dir('*.txt') ; % get all text files of the folder
N = length(files) ; % Toatl number of files
;
% Z =zeros(1,2);
% % Zz=num2str(Z);
% Pp=cell2table(Zz);
% P=table(Pp.Zz1, Pp.Zz4)
P = table('Size',[2,2],'VariableTypes',{'table', 'double'})
P.Properties.VariableNames = {'Title' 'avarray'}
for i = 1:N % loop for each file
thisfile = files(i).name ; % present file
%%do what you want
%%Find matching row in T
nameF = string(thisfile);
D= readtable(thisfile)
nameW = split(nameF,".");
nameL = nameW(1,:)+".tif";
%%readtable(Results)
k = table(Results.Label, Results.XM, Results.YM)
j= k(k.Var1==nameL, {'Var2' 'Var3'});
j.Properties.VariableNames = {'XM' 'YM'}
%%opts.ReadRowNames = {nameL} ;
%% W=zeros(3,1);
%% W = (Results,opts);
%%New table with T
% Add columns from .txt
T=table(D.XM, D.YM);
T.Properties.VariableNames = {'XM' 'YM'}
DT=delaunayTriangulation(T.XM,T.YM)
NumberofTri = (numel(DT.ConnectivityList)/3);
%Get the points of the first triangle
AveworkArray=zeros(1,2)
Avework=array2table(AveworkArray);
Avework.Properties.VariableNames={'m' 'area'};
for m=1:NumberofTri;
points= DT.ConnectivityList(m,:);
a= points(1);
b = points(2);
c=points(3);
aco=DT.Points(a,:);
bco=DT.Points(b,:);
cco=DT.Points(c,:);
ax=aco(1);
ay=aco(2);
bx=bco(1)
by=bco(2);
cx=cco(1);
cy=cco(2);
area=(((ax*(by-cy))+(bx*(cy-ay))+(cx*(ay-by)))/2);
Awork=table(m,area)
Avework=[Avework;Awork]
end
Aav=(Avework(:,2));
Aava=table2array(Aav);
Aavt= mean(Aava);
AavTab=table(nameL,Aavt);
for l = 1:size(T,1)
if T.XM >0
XN = T.XM-j.XM
YN=T.YM-j.YM
distsub=(XN-YN)
distsq=distsub.^2
dist1=distsq.^0.5
;
nempty=[0];
empty=array2table(nempty);
empty.Properties.VariableNames = {'Distance'}
dist2=array2table(dist1);
dist2.Properties.VariableNames = {'Distance'}
AvTab=[empty;dist2]
AvTab2=table2array(AvTab)
end
avarray=average(AvTab2);
end
k.Properties.VariableNames = {'Title' 'Var2' 'Var3'}
Title= k(k.Title==nameL, {'Title'})
%%P=table(Title, av);
% some function
FT=[j;T];
Pnew=table(Title, avarray);
P= [P;Pnew] ;
end
show P
  1 Commento
Guillaume
Guillaume il 1 Ott 2019
Your code is a mess, making it hard to understand. Can you at least fix the indenting (ctrl+I in matlab editor)? remove the unnecessary comments and add comments that actual explain what you're doing. There's also a lot of conversions back and forth between tables and matrices, that's probably unnecessary.
Could you attach a mat file with P and Pnew?
Your question seems to follow on from your previous one, which was answered. It's unclear if that answer was useful since it certainly wasn't taken on board in your code above.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Data Type Identification in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by