add value in array

조회 수: 2 (최근 30일)
Oman Wisni
Oman Wisni 2018년 10월 29일
댓글: Oman Wisni 2018년 10월 29일
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

채택된 답변

KSSV
KSSV 2018년 10월 29일
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
KSSV
KSSV 2018년 10월 29일
files = dir('*.bmp') ;
This will take all bmp file names.
Oman Wisni
Oman Wisni 2018년 10월 29일
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');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by