add value in array

3 vues (au cours des 30 derniers jours)
Oman Wisni
Oman Wisni le 29 Oct 2018
Commenté : Oman Wisni le 29 Oct 2018
hi,
I have foldername of image, the name of image is a1.bmp, a2.bmp, b1.bmp, b2.bmp.
I want store in array when a1 & a2.bmp the value is 1, and b1&b2.bmp the value is 2.
Here the illustration :
How can I do it in matlab ? thanks

Réponse acceptée

KSSV
KSSV le 29 Oct 2018
files = {'a1.bmp' ; 'a2.bmp' ; 'b1.bmp' ; 'b2.bmp' } ;
N = length(files) ;
iwant = zeros(N,1) ;
letter2number = @(c)1+lower(c)-'a';
for i = 1:N
[filepath,name,ext] = fileparts(files{i}) ;
k = letter2number(name) ;
iwant(i) = k(1) ;
end
  3 commentaires
KSSV
KSSV le 29 Oct 2018
files = dir('*.bmp') ;
This will take all bmp file names.
Oman Wisni
Oman Wisni le 29 Oct 2018
Sir, I already trying it, but when I input another image with different name the result before replace. I have 11 species of leaf, every species contain with 25 image. I want to save it without replacing the value. Here I attached the image what I mean and here I have code for it but still error.
try
load Target.mat
catch me
end
if exist('target','var')~=0
height = size(Input,1);
else
%Input = [];
IDName=[];
end
ID = cellstr(foldername); %String
IDName = [IDName;ID];
target = zeros(1,275);
target(1:25,:) = 1;
target(26:50,:) = 2;
target(51:75,:) = 3;
target(76:100,:) = 4;
target(101:125,:) = 5;
target(121:150,:) = 6;
target(151:175,:) = 7;
target(176:200,:) = 8;
target(201:225,:) = 9;
target(226:250,:) = 10;
target(251:275,:) = 11;
Targettable.Properties.VariableNames = target;
save('target.mat','target','targettable','IDName');

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by