I want to classify my image files into 4 classes, but I only get 0 and 1 with this code:
Target_Data = ones(1,Total_Images);
Target_Data(1:Total_Images/4) = 0;
How to add the other classes? Thank you.

 채택된 답변

Walter Roberson
Walter Roberson 2019년 5월 18일

0 개 추천

Target_Data = repmat((1:4).', Total_Images/4, 1);

댓글 수: 7

Sir @Walter say total images 10, it can be any value
>> Target_Data=repmat((1:4).', 10/4, 1);
Error using repmat
Replication factors must be a row vector of integers or integer scalars.
Qvna Lhyvnav
Qvna Lhyvnav 2019년 5월 18일
Thank you for your reply. How if I want to classify each 15 files with different values? For example, 1-15 is 1, 16-30 is 2, etc. I have 60 files and I want to have the same dimention as my training data.
Walter Roberson
Walter Roberson 2019년 5월 18일
KALYAN ACHARJYA: what you mention is a problem, but with the information given to us, the meaning of dividing into N classes is not defined for the case where the number of images is not a multiple of N.
Target_Data = repelem((1:4).', Total_Images/4, 1);
Qvna Lhyvnav
Qvna Lhyvnav 2019년 5월 18일
The code works to me, but I transpose it again before compare it to the training data. My training data has 3x60 dimension, while the code gives me 60x1 dimension. Is it possible to use repelem without transpose in the function?
Target_Data = repelem(1:4, Total_Images/4);
Qvna Lhyvnav
Qvna Lhyvnav 2019년 5월 18일
Done. Thank you for your help!

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

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 5월 18일
편집: KALYAN ACHARJYA 2019년 5월 18일

0 개 추천

May be you are confusing with logical indexing, there is nothing related to classification of images
lets say Total_Images=8, that menas Target_Data= ones(1,8)
>> Target_Data=ones(1,Total_Images)
Target_Data =
1 1 1 1 1 1 1 1
in next line Total_Images/4=2, so the next line is Target_Data(1:2)=0
>> Target_Data(1:Total_Images/4)=0
Target_Data =
0 0 1 1 1 1 1 1
It is checking the 1 D array elements from 1 to 2 (Target_Data(1:2)) equal to zero or not, its false logic, therefore it is zero,
There for 1st and 2nd elements are 0 and rest are same as initial Taret__Data.
If you do following one, lets check all Target_Data elemets, wheather 0 or not, you may get all zero in resultant target elements.
>> Target_Data(1:8)=0
Target_Data =
0 0 0 0 0 0 0 0
I didnot find any clue to classes images based on these two statements, if you can, as you now undestand the code, do modification accordingly.

댓글 수: 1

Qvna Lhyvnav
Qvna Lhyvnav 2019년 5월 18일
Thank you for your reply. I understand, but I want to make four classes (60 files with each 15 files has different values). This code works for two classes.

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

카테고리

도움말 센터File Exchange에서 Language Support에 대해 자세히 알아보기

제품

릴리스

R2017a

질문:

2019년 5월 18일

댓글:

2019년 5월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by