Convert individual values in a matrix to letters and keep remaining as numbers

1 view (last 30 days)
Hi,
I'm trying to fill in characters corresponding to elements in the array airline_names into the array Usage using the below code:
Usage = num2cell(CounterUsage);
airline_names = cellstr(['AC_ '; 'FI_ '; 'QR_ '; 'SK_C'; 'SQ_ '; 'STB '; 'STE '; 'TG_ ']);
for i=1:33
for j=1:288
if isequal(Usage(i,j),0) ;
else
Usage(i,j)=num2cell(double('AB'));
%else
%Usage(i,j) = num2str(airline_names(CounterUsage(i,j)));
end
end
end
Usage is a matrix of values from 0 to 8 where I want all non zero elements to be replaced by the corresponding element in airline_names, e.g. Usage(i,j) = 1 then 1 should be replaced by airline_names(1) = 'AC_ '
However, the above code doesn't work due to what I think might be some type/format errors..
Please help!:D
Best Regards Maria and Christian

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 1 Jun 2013
airline_names = cellstr(['AC_ '; 'FI_ '; 'QR_ '; 'SK_C'; 'SQ_ '; 'STB '; 'STE '; 'TG_ '])
usage=randi(8,8,1)
out=airline_names(usage)
  3 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 1 Jun 2013
Edited: Azzi Abdelmalek on 1 Jun 2013
airline_names = cellstr(['AC_ '; 'FI_ '; 'QR_ '; 'SK_C'; 'SQ_ '; 'STB '; 'STE '; 'TG_ '])
usage=randi(8,288,33)-1
idx=find(usage==0)
idx1=setdiff(1:numel(usage),idx)
out=cell(size(usage))
out(idx)=num2cell(0)
out(idx1)=airline_names(usage(idx1))

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!