Can't find the syntax errors
이전 댓글 표시
I am using MATLAB, SeduMi and YALMIP to implement the algorithm published here. I know I have SeDuMi and YALMIP installed correctly. Before implementing that complicated algorithm, I wanted to use the same approach on an easier problem. With that in mind I tried the code that below, but I get syntax errors. Please show me how to fix the errors. If you can get it working that's even better. The syntax errors are:
- Keyword for is underlined red with the message: "Invalid use of keyword."
- norm(residulas,Inf)); has the right most ')' underlined red with the message:"Parse error at ')': usage might be invalid MATLAB syntax."
- Keyword end is underlined red with the message: "Parse error at END: usage might be invalid MATLAB syntax."
addpath(genpath('C:\Program Files\MATLAB\R2010b\toolbox\yalmip'))
path(path,'D:\Documents and Settings\My Documents\MATLAB\SeDuMi_1_1')
path(path, 'D:\Documents and Settings\My Documents\MATLAB\SeDuMi_1_1\convr')
xvals = 1:0.1:7;
yvals = -xvals.^2+8*xvals-15.5;
residuals = zeros(length(xvals));
% a, w, phi, c are parameters to be optimized
a = sdpvar(1,1);
w = sdpvar(1,1);
phi = sdpvar(1,1);
c = sdpvar(1,1);
delta_step = sdpvar(4,1);
options = sdpsettings('solver','sedumi','usex0',1,'verbose',1);
assign(a,-10.58);
assign(w,0.47);
assign(phi,1.2);
assign(c,-9.87);
% determine values of a, w, phi, c that give a minimax
% approximation of (yvals, xvals) using y = a*cos( w*x + phi) + c
% BTW: It seems the solution is y = -10.6072*cos(0.4729*x+1.25)-9.9049
constraints = [ -11<=a<=-9, 0.35<=w<=0.7, 0.8<=phi<=1.25, -11<=c<=-6,...
norm(delta_step,2)<=0.04 ];
% 2nd argument of solvesdp is a for loop followed by norm(residuals,inf)
solvesdp(constraints,...
for k=1:length(xvals)
xval=xvals(k);
yval=yvals(k);
% gradient of (a*cos( w*x + phi) + c) WRT (a,b,phi,c)
gradient = [cos(w*xval)+phi,-a*xval*sin(w*xval)+phi,...
-a*sin(w*xval)+phi,1];
step=gradient*(delta_step);
residuals(k)=yval-(a*cos(w*xval+phi)-c)+step;
end
norm(residuals,Inf));
solution = [double(a),double(w),double(phi),double(c)];
댓글 수: 5
Rahul Meshram
2022년 5월 18일
clear all; FileName1 = uigetfile("*", "); im101 = imread(FileName1); im102 imresize(im101,[312 312]); K1=im102(:,:,.2); im103 = rgb2gray(im102); im103 = imbinarize(im103); imshow(im103); FileName2 = uigetfile("** ,"); im201 = imread(FileName2); im202= imresize(im201,[312 312]); K2 =im202(:,:,2); im203 = rgb2gray(im202); im203= imbinarize(im203); imshow(im203);
P1 = detectSURFFeatures(im103);
strongest = P1.selectStrongest(200);
plot(strongest);
P2 = detectSURFFeatures(im203);
[f1,valid_points1] = extractFeatures(im103,P1); [f2,valid_points2] = extractFeatures (im203,P2);
indexPairs = matchFeatures(f1,f2);
disp(indexPairs); disp(length(indexPairs));
matchedPoints1 = valid_points 1 (indexPairs(:,1));
matchedPoints2 = valid_points2(indexPairs(:,2));
figure; ax = axes; showMatchedFeatures(im103,im203,matchedPoints1,matchedPoints2, montage','Parent',ax)
title('Counterfeit Currency Detection');
if length(indexPairs) >=80 msgbox('Currency Is Real");
else msgbox('Currency Is Counterfeit'); end
Here also syntax error occurred. How can I solve
Walter Roberson
2022년 5월 18일
im102 imresize(im101,[312 312])
That line would be interpreted as a request to call a function named im102 passing in a character vector 'imresize(im101,[312 312])'
FileName1 = uigetfile("*",");
That would create a scalar string object "*" for the first parameter. The second parameter would be a syntax error as double-quote by itself is not valid syntax in MATLAB. Perhaps you intended two single quotes in a row, '' instead of a single " . However, to be consistent with using a string scalar for the first parameter if the intention is to pass emptiness for the second parameter, it would be more readable to pass ""
K1=im102(:,:,.2);
That line is consistent with the possibility that im102 is a function. It is not consistent with the possibility that it is a variable, because using 0.2 as an index will not work.
showMatchedFeatures(im103,im203,matchedPoints1,matchedPoints2, montage','Parent',ax)
That line contains a call to the function named montage() with no arguments, and if that does not error out, it does a conjugate transpose of the return value. I have to wonder whether the intent was to instead use the character vector 'montage' with the leading single quote.
Johan Löfberg
2022년 5월 19일
편집: Johan Löfberg
2022년 5월 19일
Do note that there is no official command in YALMIP, since a decade back, called solvesdp https://yalmip.github.io/tutorial/basics/. Nor is there any official command called double.
Johan Löfberg
2022년 5월 19일
and there is no reason to assign initials, as sedumi does not support warmstarts (and even if it did, warmstarting primal-dual solvers with primals only will never help more than absolutely marginally)
Walter Roberson
2022년 5월 19일
It looks as if optimize() was available at least as early as 2010, but that solvesdp was being worked on up to at least 2014.
채택된 답변
추가 답변 (1개)
Alan Weiss
2013년 5월 2일
0 개 추천
Please show us the errors you get.
Alan Weiss
MATLAB mathematical toolbox documentation
카테고리
도움말 센터 및 File Exchange에서 Coordinate Transformations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!