How to delete empty spaces in matrix?
Ältere Kommentare anzeigen
So I have been trying to remove the empty spaces created by the matrix not selected. The matrix (not shown in code) is identified as MATERIALS(:,:,:). So I tried using:
Y(cellfun('isempty',Y))= [];
but it continues to tell me cellfun works only on cells. Since it said that, I was wondering how to convert all the data into cell arrays but I do not think that is the case.
So, is if there is a way to remove empty spaces from the matrix?
also I was thinking that char (to produce vertical data) was converting the matrix into character array. So would you have to convert that into cell arrays?
so this is part of the code. If it helps.
MATERIALS{1,1,1} = 'KAOWOOL';
MATERIALS{1,1,2} = 'AL';
MATERIALS{1,1,3} = 'PMMA';
MATERIALS{1,2,3} = 'RPMMA';
MATERIALS{1,1,4} = 'HIPS';
MATERIALS{1,2,4} = 'RHIPS';
MATERIALS{1,1,5} = 'Kydex';
MATERIALS{1,2,5} = 'RKydex';
MATERIALS{1,1,6} = 'CB_A';
MATERIALS{1,2,6} = 'RCB_A';
MATERIALS{1,1,7} = 'PEI';
MATERIALS{1,2,7} = 'RPEI';
MATERIALS{1,1,8} = 'PET';
MATERIALS{1,2,8} = 'RPET';
MATERIALS{1,1,9} = 'POM';
MATERIALS{1,2,9} = 'RPOM';
MATERIALS{1,1,10} = 'ABS';
MATERIALS{1,2,10} = 'RABS';
MATERIALS{2,1,11} = 'MIXTURES';
index_selected = get(handles.cmp_list,'Value');
NI = size(index_selected,2);
Matl_index=[10, 2, 6, 4, 1, 5, 7, 8, 3, 9];
for j = 1:NI %Thermodynamics
a{j}=char(MATERIALS{:,1,Matl_index(index_selected(j))});
end
b=char(MATERIALS{:,1,11}); %Mixtures
for j = 1:NI %Kinematics
c{j}=char(MATERIALS{:,2,Matl_index(index_selected(j))});
end
X = char(a);
Z = char(c);
Y = char(X,b,Z);
% C = cellstr(Y); %testing
% C(~cellfun('isempty',C)) = []; %testing
FileName = uiputfile('*.cmp','Save as');
dlmwrite(FileName,Y,'delimiter', '', 'newline', 'pc');
2 Kommentare
Guillaume
am 20 Nov. 2014
A matrix cannot have empty elements. If it's a matrix of char, each element is a single character, some of which can be the space character (ASCII 32) but never empty.
Because, by definition a matrix is square, you cannot remove elements (unless you remove a whole row or column) without reshaping it.
So, you need to better define what you mean by empty spaces ( ' ' or '' ?) and what you mean to obtain.
Your example code is not very useful without the input variables. What would be more useful is a simplified example input matrix and the expected result.
Tamfor Dulin
am 20 Nov. 2014
Bearbeitet: Tamfor Dulin
am 20 Nov. 2014
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Thermodynamics and Heat Transfer finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!