フィルターのクリア

how to remove image extension so that only numbered name can be stored in a database

4 ビュー (過去 30 日間)
hp
hp 2018 年 9 月 9 日
コメント済み: hp 2018 年 9 月 28 日
hi .. i have some features stored in a .mat file, and i want to concatenate numbered image names( without their extension) to the same .mat file. so that i can sort image names along with sorting its numerical features.. how to do plz help? say eg: if a.mat contains features as follows
12 2.3344 3.22 4.22 123.jpg
as i have written this example the mat file contains 5 columns but in fifth column, we have numbered name of an image including its extension i.e. .jpg. how to remove that extension & store only 123 as its name.

採用された回答

dpb
dpb 2018 年 9 月 9 日
n=sscanf(fname,'%d.jpg')
or
[~,name]=fileparts(fname);
n=str2num(n);

その他の回答 (2 件)

Image Analyst
Image Analyst 2018 年 9 月 9 日
So after you extract the variables from your .mat file, do you have a string '12 2.3344 3.22 4.22 123.jpg'? If so, then do you want to take each number in the string and create a filename from it? Try
% Create sample string.
str = '12 2.3344 3.22 4.22 123.jpg'
% Convert to numbers
numbers = str2num(str(1:end-4))
% Now sort the numbers
sortedNumbers = sort(numbers, 'ascend')
% Now go through, saving files with each number but no extension (which is probably not a wise idea).
folder = pwd; % Wherever you want...
for k = 1 : length(numbers)
fullFileName = fullfile(folder, num2str(numbers(k)))
% Now do whatever you want with that filename
end
However, I don't see what sorting gets you - not sure why you wanted that. Plus you can use strsplit() and not bother about converting them to numbers. Why do you want them as numbers instead of keeping them as substrings?
Unfortunately you have not read this link and forgot to attach your .mat file. Attach it if you want more help.
  7 件のコメント
hp
hp 2018 年 9 月 11 日
Thank you so much this clarification i wanted.. as you have mentioned its a better idea to consider image names as rownames... it may help me i will try this. thank you for the Answer.
dpb
dpb 2018 年 9 月 12 日
NB: The usage as a Row Name will require limiting the string to one that is a valid ML variable name.

サインインしてコメントする。


hp
hp 2018 年 9 月 11 日
all Image names which are in Images_names.mat file have to copied to the last column of the FEATUREdb.mat and if i apply sortrows ....all columns has to be sorted... plz help...
  1 件のコメント
hp
hp 2018 年 9 月 28 日
I got answer from Image analyst... using fileparts to extract the filenames -works... thank you...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by