How to output a table in Matlab by altering the function statement?Matlab: Optimizing speed of function call and cosine sign-finding in a loopMatlab function input for a input that changeshow to solve numerically space time dependent differential equation in matlabSolving Set of Second Order ODEs with Matlab ODE45 functionZero Vector Returned errorMatlab Table / Dataset type optimizationHow can MATLAB use the inputdlg function to process a symbolic function input?Runge-kutta for coupled ODEsUsing “subs” Function to Evaluate Output of “dsolve” Give Extra Output in MaltabHow to specify a function for use with improved euler code

Co-author wants to put their current funding source in the acknowledgements section because they edited the paper

Would Buddhists help non-Buddhists continuing their attachments?

Need to read my home electrical Meter

First Program Tic-Tac-Toe

If I arrive in the UK, and then head to mainland Europe, does my Schengen visa 90 day limit start when I arrived in the UK, or mainland Europe?

Gravitational Force Between Numbers

Heat lost in ideal capacitor charging

A burglar's sunglasses, a lady's odyssey

USPS Back Room - Trespassing?

On San Andreas Speedruns, why do players blow up the Picador in the mission Ryder?

How can I properly write this equation in Latex?

Why sampling a periodic signal doesn't yield a periodic discrete signal?

Is "vegetable base" a common term in English?

Why did Jon Snow admit his fault in S08E06?

Is keeping the forking link on a true fork necessary (Github/GPL)?

How was Daenerys able to legitimise Gendry?

Python program for fibonacci sequence using a recursive function

Creating second map without labels using QGIS?

Why does the Starter Set wizard have six spells in their spellbook?

Do copyright notices need to be placed at the beginning of a file?

Why does Bran want to find Drogon?

Is superuser the same as root?

Can a ring of spell storing and access to Find spells produce an endless menagerie?

How to let other coworkers know that I don't share my coworker's political views?



How to output a table in Matlab by altering the function statement?


Matlab: Optimizing speed of function call and cosine sign-finding in a loopMatlab function input for a input that changeshow to solve numerically space time dependent differential equation in matlabSolving Set of Second Order ODEs with Matlab ODE45 functionZero Vector Returned errorMatlab Table / Dataset type optimizationHow can MATLAB use the inputdlg function to process a symbolic function input?Runge-kutta for coupled ODEsUsing “subs” Function to Evaluate Output of “dsolve” Give Extra Output in MaltabHow to specify a function for use with improved euler code






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















My technique of making a vector out of "column" variables in a table only works part of the time. What is different about K1 from index in the following code? I am debugging a numerical method and I need the columns index, X, K1, K2, K, Y. All works fine until I add K1, K2, and K? How to do?



MM



What is needed is to properly initalize K1, k1, K2, k2, K, and k.
Corrected code is below.



FUNCTION CODE:



function [index,X,K1,K2,K,Y] = impeulerT(x,y,x1,n)
% modified version of Improved Euler method found in
% Elementary Differential Equations by Edwards and Penney
X=x; % initial x
Y=y; % initial y
x1 = x1; % final x
n = n; % number of subintervals
h = (x1-x)/n; % step size
index = 0; % initialize index
k1=0; K1=k1; % initialize k1
k2=0; K2=k2; % initialize k2
k=0; K=k; % initialize k
for i=1:n; % begin loop
k1=f(x,y); % first slope
k2=f(x+h,y+h*k1); % second slope
k=(k1+k2)/2; % average slope
x=x+h; % new x
y=y+h*k; % new y
X=[X;x]; % update x-column
Y=[Y;y]; % update y-column
index = [index;i]; % update index-column
K1=[K1;k1]; % update K1 column
K2=[K2;k2]; % update K2 column
K= [K;k]; % update K column
end % end loop
ImprovedEulerTable=table(index,X,K1,K2,K,Y)
clear
end


CALL CODE:



[index,X,K1,K2,K,Y] = impeulerT(0,1,1,10);


LOG:



Output argument "index" (and maybe others) not
assigned during call to "impeulerT".









share|improve this question
























  • Please don’t edit the answer into your question, it invalidates the answer.

    – Cris Luengo
    Mar 24 at 16:20

















0















My technique of making a vector out of "column" variables in a table only works part of the time. What is different about K1 from index in the following code? I am debugging a numerical method and I need the columns index, X, K1, K2, K, Y. All works fine until I add K1, K2, and K? How to do?



MM



What is needed is to properly initalize K1, k1, K2, k2, K, and k.
Corrected code is below.



FUNCTION CODE:



function [index,X,K1,K2,K,Y] = impeulerT(x,y,x1,n)
% modified version of Improved Euler method found in
% Elementary Differential Equations by Edwards and Penney
X=x; % initial x
Y=y; % initial y
x1 = x1; % final x
n = n; % number of subintervals
h = (x1-x)/n; % step size
index = 0; % initialize index
k1=0; K1=k1; % initialize k1
k2=0; K2=k2; % initialize k2
k=0; K=k; % initialize k
for i=1:n; % begin loop
k1=f(x,y); % first slope
k2=f(x+h,y+h*k1); % second slope
k=(k1+k2)/2; % average slope
x=x+h; % new x
y=y+h*k; % new y
X=[X;x]; % update x-column
Y=[Y;y]; % update y-column
index = [index;i]; % update index-column
K1=[K1;k1]; % update K1 column
K2=[K2;k2]; % update K2 column
K= [K;k]; % update K column
end % end loop
ImprovedEulerTable=table(index,X,K1,K2,K,Y)
clear
end


CALL CODE:



[index,X,K1,K2,K,Y] = impeulerT(0,1,1,10);


LOG:



Output argument "index" (and maybe others) not
assigned during call to "impeulerT".









share|improve this question
























  • Please don’t edit the answer into your question, it invalidates the answer.

    – Cris Luengo
    Mar 24 at 16:20













0












0








0








My technique of making a vector out of "column" variables in a table only works part of the time. What is different about K1 from index in the following code? I am debugging a numerical method and I need the columns index, X, K1, K2, K, Y. All works fine until I add K1, K2, and K? How to do?



MM



What is needed is to properly initalize K1, k1, K2, k2, K, and k.
Corrected code is below.



FUNCTION CODE:



function [index,X,K1,K2,K,Y] = impeulerT(x,y,x1,n)
% modified version of Improved Euler method found in
% Elementary Differential Equations by Edwards and Penney
X=x; % initial x
Y=y; % initial y
x1 = x1; % final x
n = n; % number of subintervals
h = (x1-x)/n; % step size
index = 0; % initialize index
k1=0; K1=k1; % initialize k1
k2=0; K2=k2; % initialize k2
k=0; K=k; % initialize k
for i=1:n; % begin loop
k1=f(x,y); % first slope
k2=f(x+h,y+h*k1); % second slope
k=(k1+k2)/2; % average slope
x=x+h; % new x
y=y+h*k; % new y
X=[X;x]; % update x-column
Y=[Y;y]; % update y-column
index = [index;i]; % update index-column
K1=[K1;k1]; % update K1 column
K2=[K2;k2]; % update K2 column
K= [K;k]; % update K column
end % end loop
ImprovedEulerTable=table(index,X,K1,K2,K,Y)
clear
end


CALL CODE:



[index,X,K1,K2,K,Y] = impeulerT(0,1,1,10);


LOG:



Output argument "index" (and maybe others) not
assigned during call to "impeulerT".









share|improve this question
















My technique of making a vector out of "column" variables in a table only works part of the time. What is different about K1 from index in the following code? I am debugging a numerical method and I need the columns index, X, K1, K2, K, Y. All works fine until I add K1, K2, and K? How to do?



MM



What is needed is to properly initalize K1, k1, K2, k2, K, and k.
Corrected code is below.



FUNCTION CODE:



function [index,X,K1,K2,K,Y] = impeulerT(x,y,x1,n)
% modified version of Improved Euler method found in
% Elementary Differential Equations by Edwards and Penney
X=x; % initial x
Y=y; % initial y
x1 = x1; % final x
n = n; % number of subintervals
h = (x1-x)/n; % step size
index = 0; % initialize index
k1=0; K1=k1; % initialize k1
k2=0; K2=k2; % initialize k2
k=0; K=k; % initialize k
for i=1:n; % begin loop
k1=f(x,y); % first slope
k2=f(x+h,y+h*k1); % second slope
k=(k1+k2)/2; % average slope
x=x+h; % new x
y=y+h*k; % new y
X=[X;x]; % update x-column
Y=[Y;y]; % update y-column
index = [index;i]; % update index-column
K1=[K1;k1]; % update K1 column
K2=[K2;k2]; % update K2 column
K= [K;k]; % update K column
end % end loop
ImprovedEulerTable=table(index,X,K1,K2,K,Y)
clear
end


CALL CODE:



[index,X,K1,K2,K,Y] = impeulerT(0,1,1,10);


LOG:



Output argument "index" (and maybe others) not
assigned during call to "impeulerT".






matlab output






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 16:20









Cris Luengo

25k62356




25k62356










asked Mar 23 at 23:26









Mary A. MarionMary A. Marion

1831214




1831214












  • Please don’t edit the answer into your question, it invalidates the answer.

    – Cris Luengo
    Mar 24 at 16:20

















  • Please don’t edit the answer into your question, it invalidates the answer.

    – Cris Luengo
    Mar 24 at 16:20
















Please don’t edit the answer into your question, it invalidates the answer.

– Cris Luengo
Mar 24 at 16:20





Please don’t edit the answer into your question, it invalidates the answer.

– Cris Luengo
Mar 24 at 16:20












1 Answer
1






active

oldest

votes


















0














You are clearing your variables before you can return them. The error you receive can be explained here.



To fix your code, just simply remove or comment the clear statement after you create your table:



function [index,X,K1,K2,K,Y] = impeulerT(x,y,x1,n)
% modified version of Improved Euler method found in
% Elementary Differential Equations by Edwards and Penney
X=x; % initial x
Y=y; % initial y
x1 = x1; % final x
n = n; % number of subintervals
h = (x1-x)/n; % step size
index = 0; % initialize index
k1=0; K1=k1; % initialize k1
k2=0; K2=k2; % initialize k2
k=0; K=k; % initialize k
for i=1:n; % begin loop
k1=(x/y); % first slope
k2=(x+h)/(y+h*k1); % second slope
k=(k1+k2)/2; % average slope
x=x+h; % new x
y=y+h*k; % new y
X=[X;x]; % update x-column
Y=[Y;y]; % update y-column
index = [index;i]; % update index-column
K1=[K1;k1]; % update K1 column
K2=[K2;k2]; % update K2 column
K= [K;k]; % update K column
end % end loop
ImprovedEulerTable=table(index,X,K1,K2,K,Y);
end


In general, you don't have to worry about clearing your variables inside a called function, since those variables only stay within that function's workspace. The only variables that change are the ones that are returned. Read more here on how functions work with workspaces.






share|improve this answer























  • Thanks. The clear had been taken out but I see it somehow got put back into the code. MM

    – Mary A. Marion
    Mar 24 at 14:42











  • You may want to leave the clear statement in the original question, for context for anyone else who may have this problem in the future.

    – medicine_man
    Mar 24 at 14:42












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319315%2fhow-to-output-a-table-in-matlab-by-altering-the-function-statement%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You are clearing your variables before you can return them. The error you receive can be explained here.



To fix your code, just simply remove or comment the clear statement after you create your table:



function [index,X,K1,K2,K,Y] = impeulerT(x,y,x1,n)
% modified version of Improved Euler method found in
% Elementary Differential Equations by Edwards and Penney
X=x; % initial x
Y=y; % initial y
x1 = x1; % final x
n = n; % number of subintervals
h = (x1-x)/n; % step size
index = 0; % initialize index
k1=0; K1=k1; % initialize k1
k2=0; K2=k2; % initialize k2
k=0; K=k; % initialize k
for i=1:n; % begin loop
k1=(x/y); % first slope
k2=(x+h)/(y+h*k1); % second slope
k=(k1+k2)/2; % average slope
x=x+h; % new x
y=y+h*k; % new y
X=[X;x]; % update x-column
Y=[Y;y]; % update y-column
index = [index;i]; % update index-column
K1=[K1;k1]; % update K1 column
K2=[K2;k2]; % update K2 column
K= [K;k]; % update K column
end % end loop
ImprovedEulerTable=table(index,X,K1,K2,K,Y);
end


In general, you don't have to worry about clearing your variables inside a called function, since those variables only stay within that function's workspace. The only variables that change are the ones that are returned. Read more here on how functions work with workspaces.






share|improve this answer























  • Thanks. The clear had been taken out but I see it somehow got put back into the code. MM

    – Mary A. Marion
    Mar 24 at 14:42











  • You may want to leave the clear statement in the original question, for context for anyone else who may have this problem in the future.

    – medicine_man
    Mar 24 at 14:42
















0














You are clearing your variables before you can return them. The error you receive can be explained here.



To fix your code, just simply remove or comment the clear statement after you create your table:



function [index,X,K1,K2,K,Y] = impeulerT(x,y,x1,n)
% modified version of Improved Euler method found in
% Elementary Differential Equations by Edwards and Penney
X=x; % initial x
Y=y; % initial y
x1 = x1; % final x
n = n; % number of subintervals
h = (x1-x)/n; % step size
index = 0; % initialize index
k1=0; K1=k1; % initialize k1
k2=0; K2=k2; % initialize k2
k=0; K=k; % initialize k
for i=1:n; % begin loop
k1=(x/y); % first slope
k2=(x+h)/(y+h*k1); % second slope
k=(k1+k2)/2; % average slope
x=x+h; % new x
y=y+h*k; % new y
X=[X;x]; % update x-column
Y=[Y;y]; % update y-column
index = [index;i]; % update index-column
K1=[K1;k1]; % update K1 column
K2=[K2;k2]; % update K2 column
K= [K;k]; % update K column
end % end loop
ImprovedEulerTable=table(index,X,K1,K2,K,Y);
end


In general, you don't have to worry about clearing your variables inside a called function, since those variables only stay within that function's workspace. The only variables that change are the ones that are returned. Read more here on how functions work with workspaces.






share|improve this answer























  • Thanks. The clear had been taken out but I see it somehow got put back into the code. MM

    – Mary A. Marion
    Mar 24 at 14:42











  • You may want to leave the clear statement in the original question, for context for anyone else who may have this problem in the future.

    – medicine_man
    Mar 24 at 14:42














0












0








0







You are clearing your variables before you can return them. The error you receive can be explained here.



To fix your code, just simply remove or comment the clear statement after you create your table:



function [index,X,K1,K2,K,Y] = impeulerT(x,y,x1,n)
% modified version of Improved Euler method found in
% Elementary Differential Equations by Edwards and Penney
X=x; % initial x
Y=y; % initial y
x1 = x1; % final x
n = n; % number of subintervals
h = (x1-x)/n; % step size
index = 0; % initialize index
k1=0; K1=k1; % initialize k1
k2=0; K2=k2; % initialize k2
k=0; K=k; % initialize k
for i=1:n; % begin loop
k1=(x/y); % first slope
k2=(x+h)/(y+h*k1); % second slope
k=(k1+k2)/2; % average slope
x=x+h; % new x
y=y+h*k; % new y
X=[X;x]; % update x-column
Y=[Y;y]; % update y-column
index = [index;i]; % update index-column
K1=[K1;k1]; % update K1 column
K2=[K2;k2]; % update K2 column
K= [K;k]; % update K column
end % end loop
ImprovedEulerTable=table(index,X,K1,K2,K,Y);
end


In general, you don't have to worry about clearing your variables inside a called function, since those variables only stay within that function's workspace. The only variables that change are the ones that are returned. Read more here on how functions work with workspaces.






share|improve this answer













You are clearing your variables before you can return them. The error you receive can be explained here.



To fix your code, just simply remove or comment the clear statement after you create your table:



function [index,X,K1,K2,K,Y] = impeulerT(x,y,x1,n)
% modified version of Improved Euler method found in
% Elementary Differential Equations by Edwards and Penney
X=x; % initial x
Y=y; % initial y
x1 = x1; % final x
n = n; % number of subintervals
h = (x1-x)/n; % step size
index = 0; % initialize index
k1=0; K1=k1; % initialize k1
k2=0; K2=k2; % initialize k2
k=0; K=k; % initialize k
for i=1:n; % begin loop
k1=(x/y); % first slope
k2=(x+h)/(y+h*k1); % second slope
k=(k1+k2)/2; % average slope
x=x+h; % new x
y=y+h*k; % new y
X=[X;x]; % update x-column
Y=[Y;y]; % update y-column
index = [index;i]; % update index-column
K1=[K1;k1]; % update K1 column
K2=[K2;k2]; % update K2 column
K= [K;k]; % update K column
end % end loop
ImprovedEulerTable=table(index,X,K1,K2,K,Y);
end


In general, you don't have to worry about clearing your variables inside a called function, since those variables only stay within that function's workspace. The only variables that change are the ones that are returned. Read more here on how functions work with workspaces.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 24 at 5:38









medicine_manmedicine_man

27113




27113












  • Thanks. The clear had been taken out but I see it somehow got put back into the code. MM

    – Mary A. Marion
    Mar 24 at 14:42











  • You may want to leave the clear statement in the original question, for context for anyone else who may have this problem in the future.

    – medicine_man
    Mar 24 at 14:42


















  • Thanks. The clear had been taken out but I see it somehow got put back into the code. MM

    – Mary A. Marion
    Mar 24 at 14:42











  • You may want to leave the clear statement in the original question, for context for anyone else who may have this problem in the future.

    – medicine_man
    Mar 24 at 14:42

















Thanks. The clear had been taken out but I see it somehow got put back into the code. MM

– Mary A. Marion
Mar 24 at 14:42





Thanks. The clear had been taken out but I see it somehow got put back into the code. MM

– Mary A. Marion
Mar 24 at 14:42













You may want to leave the clear statement in the original question, for context for anyone else who may have this problem in the future.

– medicine_man
Mar 24 at 14:42






You may want to leave the clear statement in the original question, for context for anyone else who may have this problem in the future.

– medicine_man
Mar 24 at 14:42




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319315%2fhow-to-output-a-table-in-matlab-by-altering-the-function-statement%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현