how to remove zeroes from the end of column in a matrice

1 visualizzazione (ultimi 30 giorni)
hi
i have wrritten this codes that proces data from excel file, the data file is of measurments.
[app.filenameZT,pathname] = uigetfile({'*.xls';'*.xlsx'},MultiSelect="on");
app.C=iscell(app.filenameZT(1,2));
if app.C==1
app.LengthZT=length(app.filenameZT);
else
app.LengthZT=1;
end
if app.C==1
for i=1:numel(app.filenameZT)
ZT(i)=importdata(fullfile(pathname,app.filenameZT{i}));
app.t(1:length(ZT(i).data(:,1)),i)=ZT(i).data(:,1);
app.S(1:length(ZT(i).data(:,2)),i)=ZT(i).data(:,2);
app.R(1:length(ZT(i).data(:,3)),i)=ZT(i).data(:,3).*10^(6);
app.K(1:length(ZT(i).data(:,4)),i)=ZT(i).data(:,4);
app.zT(1:length(ZT(i).data(:,5)),i)=ZT(i).data(:,5);
end
else
ZT=importdata(fullfile(pathname,app.filenameZT));
app.t=ZT.data(:,1);
app.S=ZT.data(:,2);
app.R=ZT.data(:,3);
app.K=ZT.data(:,4);
app.zT=ZT.data(:,5);
end
if app.C==1
figure (1)
plot(app.t,app.S,'linewidth',2);
hold on
for i=1:numel(app.filenameZT)
plot(app.t(i),app.S(i),'linewidth',2);
end
title('Seebeck Coefficient','fontweight','bold','fontsize',22)
xlabel('T[C]','fontweight','bold','fontsize',22)
ylabel ('\alpha[\muV/K]','fontweight','bold','fontsize',22)
legend (app.filenameZT);
grid minor
hold off
%ploting ressetivity
figure (2)
plot(app.t,app.R,'linewidth',2);
hold on
for i=1:numel(app.filenameZT)
plot(app.t(i),app.R(i),'linewidth',2);
end
title('Electrical Resistivity','fontweight','bold','fontsize',22)
xlabel('T[C]','fontweight','bold','fontsize',22)
ylabel('\rho[\mu\Omega*cm]','fontweight','bold','fontsize',22)
grid minor
legend (app.filenameZT);
hold off
figure (3)%% ploting kappa
plot(app.t,app.K,'linewidth',2);
hold on
for i=1:numel(app.filenameZT)
plot(app.t(i),app.K(i),'linewidth',2);
end
title('Thermal Conductivity','fontweight','bold','fontsize',22)
xlabel('T[C]','fontweight','bold','fontsize',22)
ylabel('\kappa[W/cm*C]','fontweight','bold','fontsize',22)
grid minor
legend (app.filenameZT);
hold off
figure (4)%% ploting zT
plot(app.t,app.zT,'linewidth',2);
hold on
for i=1:numel(app.filenameZT)
plot(app.t(i),app.zT(i),'linewidth',2);
end
title('Figure of Merit zT','fontweight','bold','fontsize',22)
xlabel('T[C]','fontweight','bold','fontsize',22)
ylabel('zT','fontweight','bold','fontsize',22)
grid minor
legend (app.filenameZT);
hold off
else
figure (1)
plot(app.t,app.S,'color','b','linewidth',2);
hold on
plot(app.t,app.S,'color','r','linewidth',2);
title('Seebeck Coefficient','fontweight','bold','fontsize',22)
xlabel('T[C]','fontweight','bold','fontsize',22)
ylabel ('\alpha[\muV/K]','fontweight','bold','fontsize',22)
legend (app.filenameZT);
grid minor
hold off
%ploting ressetivity
figure (2)
plot(app.t,app.R,'color','b','linewidth',2);
hold on
plot(app.t,app.R,'color','r','linewidth',2);
title('Electrical Resistivity','fontweight','bold','fontsize',22)
xlabel('T[C]','fontweight','bold','fontsize',22)
ylabel('\rho[\mu\Omega*cm]','fontweight','bold','fontsize',22)
grid minor
legend (app.filenameZT);
hold off
figure (3)%% ploting kappa
plot(app.t,app.K,'color','b','linewidth',2);
hold on
plot(app.t,app.K,'color','r','linewidth',2);
title('Thermal Conductivity','fontweight','bold','fontsize',22)
xlabel('T[C]','fontweight','bold','fontsize',22)
ylabel('\kappa[W/cm*C]','fontweight','bold','fontsize',22)
grid minor
legend (app.filenameZT);
hold off
figure (4)%% ploting zT
plot(app.t,app.zT,'color','b','linewidth',2);
hold on
plot(app.t,app.zT,'color','r','linewidth',2);
title('Figure of Merit zT','fontweight','bold','fontsize',22)
xlabel('T[C]','fontweight','bold','fontsize',22)
ylabel('zT','fontweight','bold','fontsize',22)
grid minor
legend (app.filenameZT);
hold off
end
the problem is that not all the file have the same length of data, so what happens is that in the end of the shorter length data zeroes are add, how can i delete those zeroes at the end of the columns?
files to use the code are attached

Risposte (1)

Walter Roberson
Walter Roberson il 21 Mag 2023
after the importdata,
lastused = find(any(zT(i).Data,2),1,'last');
zT(i).Data = zT(i).Data(1:lastused,:);
  2 Commenti
Dolev
Dolev il 22 Mag 2023
ok that works but i still get zeros when i plot the data with the apllied range
Walter Roberson
Walter Roberson il 22 Mag 2023
If different columns have different number of trailing 0 and you want to trim each one independently to remove the trailing 0, then unless you replace the values with something else (such as nan) you cannot store the result as a table() object. It also appear to me that your plotting would give you problems, unless you trimmed down t for each variable indepdently.

Accedi per commentare.

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by