Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters
이전 댓글 표시
This is the code that I have so far. Up until t = linspace(0,2*pi); I do not get any errors. I'm unsure if i have to start a new thread for the second part of this question, but I'm also wondering how would one be able to write a generic code for this type of task.
x = -1 + 2.*rand (1,n)
y = -1 + 2.*rand (1,n)
appr = (sum(x.*sin(1./x)<=1)/n)*4
plot(x(x.*sin(1./x)<=1),y(x.*sin(1./x)<=1),".", ... "Color",[0.3 0.7 0.5], "MarkerSize",10)
hold on
plot(x(x.*sin(1./x0,y(x.*sin(1./x),".", ... "Color", [0.7 0.5 0.3], "MarkerSize",10)
t = linspace(0,2*pi);
plot(cos(t),sin(t),’LineWidth’,3,’Color’,[0.1 0.3 0.5])
답변 (1개)
I had to guess about what you are trying to do.
n = 50;
x = -1 + 2.*rand (1,n)
y = -1 + 2.*rand (1,n)
appr = (sum(x.*sin(1./x)<=1)/n)*4
plot(x(x.*sin(1./x)<=1),y(x.*sin(1./x)<=1),".", ...
"Color",[0.3 0.7 0.5], "MarkerSize",10)
hold on
plot(x(x.*sin(1./x)>1),y(x.*sin(1./x)>1),".", ...
"Color", [0.7 0.5 0.3], "MarkerSize",10)
t = linspace(0,2*pi);
plot(cos(t),sin(t),"LineWidth",3,"Color",[0.1 0.3 0.5])
댓글 수: 5
Tomas
2023년 5월 2일
Walter Roberson
2023년 5월 2일
Your version had
plot(x(x.*sin(1./x)<=1),y(x.*sin(1./x)<=1),".", ... "Color",[0.3 0.7 0.5], "MarkerSize",10)
Everything after the ... on a line is a comment.
Your version had
plot(x(x.*sin(1./x0,y(x.*sin(1./x),".", ... "Color", [0.7 0.5 0.3], "MarkerSize",10)
which has x0 instead of x) and is missing the ) for y(x.*sin(1./x) and is missing the >1 that I presumed are desired to indicate points that do not match with the criteria.
Walter Roberson
2023년 5월 2일
By the way, consider
mask = x.*sin(1./x)<=1;
plot(x(mask), y(mask), stuff)
plot(x(~mask), y(~mask), stuff)
Much simpler and much less error prone.
Tomas
2023년 5월 2일
Image Analyst
2023년 5월 2일
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
