matlab

Add the resulting array of each loop to a cell

自作多情 提交于 2021-02-17 05:52:09
问题 I have some algorithm including a while loop: while (condition) % do something and return a result array B end Let's say: -Loop 1: B1=[1 2 3 4 5....9]; -Loop 2: B2=[10 11 12....15]; -Loop 3: B3=[16 17 18 19] ; -Loop 4: B4=[20 21 22....30]; How can I create a cell A={B1,B2,B3,B4} when the loop is finished? For my real data, the while loop may be looping 100 times or more, the above is a simplification. 回答1: You can make use of the end keyword % Initialise empty cell array A = {}; while

DYMOLA: opc server how to initialize using dsin.txt or a mat file using MATLAB

若如初见. 提交于 2021-02-17 05:52:07
问题 I created an OPC server in DYMOLA, now I have this in DYMOSIM to click and initialize using a ".MAT" file of a dsin.txt Now I created a GUI file in MATLAB, and take input for variables and created a mat file >>save FLUID_INITIALISE area volume density Now I want to initialize this using MATLAB I can do this >>write(Initialize,1) //To initialize a previous data I know can do this using dymola , SIMULATION > CONTINUE > IMPORT BUT I WANT TO INITIALIZE IT USING MATLAB normal MAT FILE LOOKS LIKE

DYMOLA: opc server how to initialize using dsin.txt or a mat file using MATLAB

[亡魂溺海] 提交于 2021-02-17 05:52:05
问题 I created an OPC server in DYMOLA, now I have this in DYMOSIM to click and initialize using a ".MAT" file of a dsin.txt Now I created a GUI file in MATLAB, and take input for variables and created a mat file >>save FLUID_INITIALISE area volume density Now I want to initialize this using MATLAB I can do this >>write(Initialize,1) //To initialize a previous data I know can do this using dymola , SIMULATION > CONTINUE > IMPORT BUT I WANT TO INITIALIZE IT USING MATLAB normal MAT FILE LOOKS LIKE

MATLAB: plot in a loop

Deadly 提交于 2021-02-17 02:50:27
问题 I've tried to do plot inside of a loop and it prints only the last plot. How can i fix it? I've tried to use hold on and drawnow after the plot definition but it didn't work. This is my code: for t=1:5 alive = Game(World , Generations, speed); plot(hplot2,1:Generations,alive); end 回答1: hold on should work. Try this: figure hplot2=gca; hold on for t=1:5 alive = rand(1,Generations); plot(hplot2,1:Generations,alive); end 回答2: Sticking in a "figure" has always worked for me. for t=1:5 alive =

MATLAB: plot in a loop

拈花ヽ惹草 提交于 2021-02-17 02:49:45
问题 I've tried to do plot inside of a loop and it prints only the last plot. How can i fix it? I've tried to use hold on and drawnow after the plot definition but it didn't work. This is my code: for t=1:5 alive = Game(World , Generations, speed); plot(hplot2,1:Generations,alive); end 回答1: hold on should work. Try this: figure hplot2=gca; hold on for t=1:5 alive = rand(1,Generations); plot(hplot2,1:Generations,alive); end 回答2: Sticking in a "figure" has always worked for me. for t=1:5 alive =

MATLAB: plot in a loop

前提是你 提交于 2021-02-17 02:48:13
问题 I've tried to do plot inside of a loop and it prints only the last plot. How can i fix it? I've tried to use hold on and drawnow after the plot definition but it didn't work. This is my code: for t=1:5 alive = Game(World , Generations, speed); plot(hplot2,1:Generations,alive); end 回答1: hold on should work. Try this: figure hplot2=gca; hold on for t=1:5 alive = rand(1,Generations); plot(hplot2,1:Generations,alive); end 回答2: Sticking in a "figure" has always worked for me. for t=1:5 alive =

How to add data to existing XLSX file in MATLAB every time using a push button?

你说的曾经没有我的故事 提交于 2021-02-17 02:38:40
问题 I have a function which generates some variable, like score, right, wrong, unanswered. This function is called using a push button. The problem is how can I add/append these values generated by a function to an XLSX file every time? Or, how to create a MAT file so that it can be added? What may be a possible solution? 回答1: The challenge involved in appending to a xls file is knowing its last row, to avoid overwriting data with the xlswrite command. I'd suggest taking a look at this file

How to add data to existing XLSX file in MATLAB every time using a push button?

假装没事ソ 提交于 2021-02-17 02:37:04
问题 I have a function which generates some variable, like score, right, wrong, unanswered. This function is called using a push button. The problem is how can I add/append these values generated by a function to an XLSX file every time? Or, how to create a MAT file so that it can be added? What may be a possible solution? 回答1: The challenge involved in appending to a xls file is knowing its last row, to avoid overwriting data with the xlswrite command. I'd suggest taking a look at this file

Find index of last occurrence for each value

筅森魡賤 提交于 2021-02-16 20:01:53
问题 I have a vector like this : >> v = [1 1 1 2 2 3 4 4 4 4 4 5 5]' v = 1 1 1 2 2 3 4 4 4 4 4 5 5 The vector is sorted. There can be any number of each values. I need to find the index of the last occurence of each value. In this case, it would return this : answer = 3 % index of the last occurence of "1" 5 % index of the last occurence of "2" 6 % index of the last occurence of "3" 11 % index of the last occurence of "4" 13 % index of the last occurence of "5" 回答1: Thanks to @trumpetlicks, the

Find index of last occurrence for each value

此生再无相见时 提交于 2021-02-16 20:01:19
问题 I have a vector like this : >> v = [1 1 1 2 2 3 4 4 4 4 4 5 5]' v = 1 1 1 2 2 3 4 4 4 4 4 5 5 The vector is sorted. There can be any number of each values. I need to find the index of the last occurence of each value. In this case, it would return this : answer = 3 % index of the last occurence of "1" 5 % index of the last occurence of "2" 6 % index of the last occurence of "3" 11 % index of the last occurence of "4" 13 % index of the last occurence of "5" 回答1: Thanks to @trumpetlicks, the