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 Center および File ExchangeConvert Image Type についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by