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

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.

 Accepted Answer

More Answers (2)

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 Comments

hp's "Answer" moved here since it's a comment to me rather than an Answer (solution) to the original question:
Thank you for your answer.
What I meant to ask is, I have some numerical features stored in an mat file and I wanted to attach image names to each row of a feature vector. So when I apply distance measure function, I will get some dist values for query image to all other images, and I can sort those dist values from smallest to biggest. Then finally I can retrieve those images with smallest distance as the result for query.
So what I was trying is appending image names at the end of each feature vector(row), while sorting feature vector row according to smallest dist measure, the names are also sorted accordingly this will help in retrieval of those images which are short listed according to dist measure.
But when I was trying to horizontally concatenate numeric and string values, either mat file will be converting into strings, or sometimes it is showing dimensions mismatch.
So what to do?
You can attach the .mat file. What can we do when the mat file is not attached?
hp's "Answer" moved here:
this is what my code is ..
for k = 1:size(data, 1)
Manhattan_dist(k) = mandist(data(k, :),queryImageFeature');
end
%--------------------------------
%Add images class to manhattan ...%
load Image_names
Manhattan_dist=[Manhattan_dist,data_class,Image_names];
And the error is :
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in manhattan_RT (line 73)
Manhattan_dist=[Manhattan_dist,data_class,Image_names];
Unfortunately, the error message text is somewhat misleading when read literally in conjunction with the above; while the three arrays are all 500x1 arrays, the Image_names array is a cell array (of strings one presumes) while the other two are double arrays and "you can't do that!".
Example: for a small case--
>> n={'namea';'nameb'};
>> x=rand(2,1);y=rand(2,1);
>> whos n x y
Name Size Bytes Class Attributes
n 2x1 244 cell
x 2x1 16 double
y 2x1 16 double
>> [x y n]
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
>>
There really isn't any way to smoosh string and numeric data together excepting to put them all in a cell array which is incovenient then for the numeric as have to use the curlies "{}" to dereference the doubles.
One thing for a database purpose you might consider would be to use a table as the composite container instead...
>> t=table(x,y,n)
t =
2×3 table
x y n
_______ _______ _______
0.81472 0.12699 'namea'
0.90579 0.91338 'nameb'
>>
Then you can actually put the data together as fields, but you might find it more conducive to your purpose to use the names as row names rather than variables--
>> t=table(x,y,'RowNames',n)
t =
2×2 table
x y
_______ _______
namea 0.81472 0.12699
nameb 0.90579 0.91338
>>
Look at the section on Tables in the Data Types for more information on creating and using the table class.
BTW, I sent a documentation/error message enhancement request to TMW about improving the root-cause error message for the use case.
I've no idea whether it is feasible without incurring excessive additional overhead in the input parser or not, but figured it worth pointing out the confusion the existing error message causes in interpreting root cause.
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.
NB: The usage as a Row Name will require limiting the string to one that is a valid ML variable name.

Sign in to comment.

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 Comment

I got answer from Image analyst... using fileparts to extract the filenames -works... thank you...

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Asked:

hp
on 9 Sep 2018

Commented:

hp
on 28 Sep 2018

Community Treasure Hunt

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

Start Hunting!