Matlab codes to display a variable name with its value
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
i want a way in which i can display a variable together with its value. I have a code inwhich i am working on which can display the minimum value from some series of values of variable, but i want a code that can display the variable name of the minimum value together with the value.
here is the complete code below:
faceDatabase = imageSet('T8ATTMSE','recursive');
%Display Query Image and Database side by side
fprintf('Press Enter to select image')
pause;
[filename,pathname]=uigetfile({'*.jpg'},'Pick an image file');
galleryImage=imread([pathname,filename]);
figure;
for i=1:size(faceDatabase,2)
imageList(i)=faceDatabase(i).ImageLocation(1);
end
subplot(1,2,1);imshow(galleryImage);title('Selected Image');
subplot(1,2,2);montage(imageList);title('Database Image');
pause(0.002)
%Split Database into Training and Test sets
[training,test]=partition(faceDatabase,[0.6 0.4]);
%Extract and display Histogram of Oriented Gradient (HOG) features for
%single face
[hogFeature,visualization]=......
extractHOGFeatures(galleryImage);
figure;
imshow(galleryImage);title('Input face');
figure;
plot(visualization);title('HOG Feature');
%Extract HOG Features for Training Set
% trainingFeatures=zeros(size(training,2)*training(1).Count,139284);
trainingFeatures=[];
featureCount=1;
for i=1:size(training,2)
for j=1:training(i).Count
trainingFeatures(featureCount,:)=extractHOGFeatures(read(training(i),j));
trainingLabel{featureCount}=training(i).Description;
featureCount=featureCount+1;
end
personIndex{i}=training(i).Description;
end
queryFeatures = extractHOGFeatures(galleryImage);
A = queryFeatures;
C = double(A);
TF1 = trainingFeatures(1,:)+trainingFeatures(2,:)+trainingFeatures(3,:)+trainingFeatures(4,:);
TF2 = trainingFeatures(5,:)+trainingFeatures(6,:)+trainingFeatures(7,:)+trainingFeatures(8,:);
TF3 = trainingFeatures(9,:)+trainingFeatures(10,:)+trainingFeatures(11,:)+trainingFeatures(12,:);
TF4 = trainingFeatures(13,:)+trainingFeatures(14,:)+trainingFeatures(15,:)+trainingFeatures(16,:);
TF5 = trainingFeatures(17,:)+trainingFeatures(18,:)+trainingFeatures(19,:)+trainingFeatures(20,:);
TF6 = trainingFeatures(21,:)+trainingFeatures(22,:)+trainingFeatures(23,:)+trainingFeatures(24,:);
TF7 = trainingFeatures(25,:)+trainingFeatures(26,:)+trainingFeatures(27,:)+trainingFeatures(28,:);
TF8 = trainingFeatures(29,:)+trainingFeatures(30,:)+trainingFeatures(31,:)+trainingFeatures(32,:);
TF9 = trainingFeatures(33,:)+trainingFeatures(34,:)+trainingFeatures(35,:)+trainingFeatures(36,:);
TF10 = trainingFeatures(37,:)+trainingFeatures(38,:)+trainingFeatures(39,:)+trainingFeatures(40,:);
TF11 = trainingFeatures(41,:)+trainingFeatures(42,:)+trainingFeatures(43,:)+trainingFeatures(44,:);
TF12 = trainingFeatures(45,:)+trainingFeatures(46,:)+trainingFeatures(47,:)+trainingFeatures(48,:);
TF13 = trainingFeatures(49,:)+trainingFeatures(50,:)+trainingFeatures(51,:)+trainingFeatures(52,:);
TF14 = trainingFeatures(53,:)+trainingFeatures(54,:)+trainingFeatures(55,:)+trainingFeatures(56,:);
TF15 = trainingFeatures(57,:)+trainingFeatures(58,:)+trainingFeatures(59,:)+trainingFeatures(60,:);
TF16 = trainingFeatures(61,:)+trainingFeatures(62,:)+trainingFeatures(63,:)+trainingFeatures(64,:);
TF17 = trainingFeatures(65,:)+trainingFeatures(66,:)+trainingFeatures(67,:)+trainingFeatures(68,:);
TF18 = trainingFeatures(69,:)+trainingFeatures(70,:)+trainingFeatures(71,:)+trainingFeatures(72,:);
TF19 = trainingFeatures(73,:)+trainingFeatures(74,:)+trainingFeatures(75,:)+trainingFeatures(76,:);
TF20 = trainingFeatures(77,:)+trainingFeatures(78,:)+trainingFeatures(79,:)+trainingFeatures(80,:);
TF21 = trainingFeatures(81,:)+trainingFeatures(82,:)+trainingFeatures(83,:)+trainingFeatures(84,:);
TF22 = trainingFeatures(85,:)+trainingFeatures(86,:)+trainingFeatures(87,:)+trainingFeatures(88,:);
TF23 = trainingFeatures(89,:)+trainingFeatures(90,:)+trainingFeatures(91,:)+trainingFeatures(92,:);
TF24 = trainingFeatures(93,:)+trainingFeatures(94,:)+trainingFeatures(95,:)+trainingFeatures(96,:);
TF25 = trainingFeatures(96,:)+trainingFeatures(97,:)+trainingFeatures(99,:)+trainingFeatures(100,:);
TF26 = trainingFeatures(101,:)+trainingFeatures(102,:)+trainingFeatures(103,:)+trainingFeatures(104,:);
TF27 = trainingFeatures(105,:)+trainingFeatures(106,:)+trainingFeatures(107,:)+trainingFeatures(108,:);
TF28 = trainingFeatures(109,:)+trainingFeatures(110,:)+trainingFeatures(111,:)+trainingFeatures(112,:);
TF29 = trainingFeatures(113,:)+trainingFeatures(114,:)+trainingFeatures(115,:)+trainingFeatures(116,:);
TF30 = trainingFeatures(117,:)+trainingFeatures(118,:)+trainingFeatures(119,:)+trainingFeatures(120,:);
TF31 = trainingFeatures(121,:)+trainingFeatures(122,:)+trainingFeatures(123,:)+trainingFeatures(124,:);
TF32 = trainingFeatures(125,:)+trainingFeatures(126,:)+trainingFeatures(127,:)+trainingFeatures(128,:);
TF33 = trainingFeatures(129,:)+trainingFeatures(130,:)+trainingFeatures(131,:)+trainingFeatures(132,:);
TF34 = trainingFeatures(133,:)+trainingFeatures(134,:)+trainingFeatures(135,:)+trainingFeatures(136,:);
TF35 = trainingFeatures(137,:)+trainingFeatures(138,:)+trainingFeatures(139,:)+trainingFeatures(140,:);
TF36 = trainingFeatures(141,:)+trainingFeatures(142,:)+trainingFeatures(143,:)+trainingFeatures(144,:);
TF37 = trainingFeatures(145,:)+trainingFeatures(146,:)+trainingFeatures(147,:)+trainingFeatures(148,:);
TF38 = trainingFeatures(149,:)+trainingFeatures(150,:)+trainingFeatures(151,:)+trainingFeatures(152,:);
TF39 = trainingFeatures(153,:)+trainingFeatures(154,:)+trainingFeatures(155,:)+trainingFeatures(156,:);
TF40 = trainingFeatures(157,:)+trainingFeatures(158,:)+trainingFeatures(159,:)+trainingFeatures(160,:);
error1=immse(C,TF1);
error2=immse(C,TF2);
error3=immse(C,TF3);
error4=immse(C,TF4);
error5=immse(C,TF5);
error6=immse(C,TF6);
error7=immse(C,TF7);
error8=immse(C,TF8);
error9=immse(C,TF9);
error10=immse(C,TF10);
error11=immse(C,TF11);
error12=immse(C,TF12);
error13=immse(C,TF13);
error14=immse(C,TF14);
error15=immse(C,TF15);
error16=immse(C,TF16);
error17=immse(C,TF17);
error18=immse(C,TF18);
error19=immse(C,TF19);
error20=immse(C,TF20);
error21=immse(C,TF21);
error22=immse(C,TF22);
error23=immse(C,TF23);
error24=immse(C,TF24);
error25=immse(C,TF25);
error26=immse(C,TF26);
error27=immse(C,TF27);
error28=immse(C,TF28);
error29=immse(C,TF29);
error30=immse(C,TF30);
error31=immse(C,TF31);
error32=immse(C,TF32);
error33=immse(C,TF33);
error34=immse(C,TF34);
error35=immse(C,TF35);
error36=immse(C,TF36);
error37=immse(C,TF37);
error38=immse(C,TF38);
error39=immse(C,TF39);
error40=immse(C,TF40);
Z=min(error1:error40);
4 comentarios
Stephen23
el 17 de Oct. de 2019
Numbering variables like that is a sign that you are doing something wrong.
Copy-and-pasting code like that is a sign that you are doing something wrong.
The very inadvisable use of numbered variables means that this will not work:
Z=min(error1:error40);
and while it could be made to work, it would be complex and inefficient.
You should follow Looky's advice and keep your data in one array, then your task is easy.
Looky
el 17 de Oct. de 2019
Since I don't have a clear idea how the data from extractHOGFeatures() looks, I can only make some guesses. Here is my idea:
lastIndex=40;
for k=1:lastIndex
trFe_Index=4*(k-1)+1;
TF(k,:) = sum(trainingFeatures(trFe_Index:trFe_Index+3,:),1);
errors(k)=immse(C,TF(k,:));
end
[Z,index]=min(errors);
sprintf('error%d', index)
Consider preallocation of TF and errors if you can. Change lastIndex to your liking.
Try if it works and if not come back with the error message, including in which line an error occurs.
Respuestas (0)
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!