Parse error in function

조회 수: 7 (최근 30일)
Cameron Lewis
Cameron Lewis 2018년 3월 19일
댓글: Cameron Lewis 2018년 3월 19일
I am supposed to create a function that takes any two radii and plugs them into the hollow sphere function/formula. But the function has to know which one is larger and assign the larger value to the outer radius. I am unsure how to do this. I thought I had solved it but I am getting a parse error on the last equals sign of the if statement. Here is what I have so far:
function [v] = hollow_sphere(outer_rad, inner_rad)
v = (4*pi/3)*(outer_rad^3 - inner_rad^3);
if inner_rad > outer_rad
outer_rad = inner_rad && inner_rad = outer_rad;
end
end

채택된 답변

James Tursa
James Tursa 2018년 3월 19일
편집: James Tursa 2018년 3월 19일
Separate those two statements. E.g., this
outer_rad = inner_rad && inner_rad = outer_rad;
should be this
temp = outer_rad;
outer_rad = inner_rad
inner_rad = temp;
But you should do this prior to your calculation of v, otherwise it will have no effect.
  댓글 수: 1
Cameron Lewis
Cameron Lewis 2018년 3월 19일
It worked, thanks so much! I am very new to coding and Matlab.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by