https://ww2.mathworks.cn/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2018-06-23T06:19:15Ztag:ww2.mathworks.cn,2005:Question/4070042018-06-22T21:01:53Z2018-06-23T06:19:15ZError in using cost matrix for classification model?<p>I've been running into an error when setting up my cost matrix,</p><p>Error using classreg.learning.classif.FullClassificationModel.processCost (line 302)
Missing misclassification cost for class 1.</p><p>I set it up using</p><p>cost.ClassificationCosts = [ 0 1; 10 0];</p><p>cost.ClassNames = classNames;</p><p>Am I missing something in the way I set up my cost matrix?</p><p>Thanks</p>Sanychen Mukhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12372481-sanychen-muktag:ww2.mathworks.cn,2005:Question/4070202018-06-23T00:33:24Z2018-06-23T06:17:57ZRandomization of columns of 3 cell arrays and accessing data<p>The main goal is to randomize the columns of 3 cell arrays.
The names of the cell arrays are:</p><pre class="language-matlab">names = {'PairsEMG_walk','PairsEMG_up','PairsEMG_do'};
</pre><p>I have created an random index array Idx of length(#columnsPairsEMG_walk+#columnsPairsEMG_up+#columnsPairsEMG_do).</p><p>Its contents are values that relates to: integer = name of array and decimal = number of column of cell array
I am tying to create a new cell array concatenating the randomize data using</p><pre class="language-matlab">condition = floor(Idx); %to point to the cell array column to extract the name of my cell array
column =100*rem(Idx,1); % to pint to the column of "that" cell array
</pre><p>For example, I have:</p><pre class="language-matlab">Idx = [ 2.0400 3.1200 1.1600 1.0900 2.0800 2.0200 3.1400 3.0200 3.0600 3.0100 1.1200 1.0200 2.1400 3.1500 1.1000 3.1300 2.1000 1.0400 2.1500 3.0900 2.0900 3.1100 2.1200 2.0100 1.0800 3.1000 1.0100 1.1400 3.0500 3.0400 1.0300 3.0800 1.0500 1.0600 1.0700 2.0500 2.1100 2.0600 1.1300 3.0700 2.0700 3.0300 2.1300 1.1100 2.0300 1.1500];
</pre><p>Therefore, the first value of condition is 2 and column 4, so I have to extract column 4 from PairsEMG_up and put it in EMGInputSeries, for the next iteration, I would need to extract column 12 from PairsEMG_do, and so on.</p><p>I tried to use eval(), but I am getting an error</p><pre class="language-matlab">for i=1:length(Idx)
EMGInputSeries{i}=eval([names(condition(i)),'{',column(i),'}'])
end
</pre><p>I get: Error using eval
Argument must contain a character vector.</p><p>also tried:</p><pre> eval(['names(',condition(i),'){',column(i),'}'])</pre><p>and I get Error: The input character is not valid in MATLAB statements or expressions.</p><p>FYI, the PairEMG arrays are 3x15 cell array, and need to extract all rows of "that" column.</p><p>Thank you,</p>ErikaZhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4536604-erikaztag:ww2.mathworks.cn,2005:Question/4070282018-06-23T04:32:46Z2018-06-23T06:03:40ZHow do you get a global average at each time step so they can be summed?<p>I have a 4D array of emissions. I want the average emissions at each time step so that I can then sum all of these averages and determine the total emissions by a certain year (in this case the entire file).</p><p>I think that I need to use a loop but am not sure how. I am currently using this: mean_time=sum(squeeze(mean(mean(mean(total,1),2),3))); as time is the 4th dimension.</p>Nesha Wrighthttps://ww2.mathworks.cn/matlabcentral/profile/authors/10983406-nesha-wrighttag:ww2.mathworks.cn,2005:Question/960052012-02-27T22:41:00Z2018-06-23T05:59:17ZWhy do I get the error "Undefined function or variable"?<p>I am receiving the following error message, how can I resolve this issue?</p><pre class="error"> ??? Undefined function or variable ‹FunctionName›
??? Undefined function or method ‹FunctionName› for input arguments of type ‹ClassName›.</pre>MathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:ww2.mathworks.cn,2005:Question/1223122014-03-20T01:43:47Z2018-06-23T05:28:06Zcontour() of matrix ~= transpose of contour() of transposed matrix?<p>The intention of this code is to produce two images, which should be mirror images of each other along the diagonal:</p><pre> %
a=[-50 -50 -50 -3.81;-50 .24 -50 -50; -50 -.55 .56 -50; -50 -50 -50 -50];
b=[1 2 3 4];
c=[-7 0];
%
figure;
contour (b, b', a, c);
figure;
contour (b', b, a', c);</pre><p>The outside contours (-7) do look like mirror images of each other; the inside contours (0) are completely different. The first figure shows a single contour, while the second one shows two separate contours.</p><p>Any idea what is going on here, and is there a way to make these two cases produce the expected results? Of course, this test case was extracted from a much larger actual case.</p>Michaelhttps://ww2.mathworks.cn/matlabcentral/profile/authors/3092320-michaeltag:ww2.mathworks.cn,2005:Question/4070312018-06-23T05:25:00Z2018-06-23T05:25:00ZMatlab startup error..please help..whenever i open matlab and go to simulink..this error occurs<p>MATLAB crash <a href = "file:C">file:C</a>:\Users\Aditya\AppData\Local\Temp\matlab_crash_dump.168-1:</p><p>--------------------------------------------------------------------------------
Access violation detected at Sat Jun 23 10:52:45 2018 +0530
--------------------------------------------------------------------------------</p><p>Configuration:
Crash Decoding : Disabled - No sandbox or build area path
Crash Mode : continue (default)
Default Encoding : windows-1252
Deployed : false
Graphics Driver : Unknown hardware
Graphics card 1 : Advanced Micro Devices, Inc. ( 0x1002 ) AMD Radeon R5 M335 Version 21.19.148.32768 (2016-12-6)
Graphics card 2 : Intel Corporation ( 0x8086 ) Intel® HD Graphics 520 Version 23.20.16.4973 (2018-2-28)
Java Version : Java 1.8.0_144-b01 with Oracle Corporation Java HotSpot™ 64-Bit Server VM mixed mode
MATLAB Architecture : win64
MATLAB Entitlement ID : 6257193
MATLAB Root : C:\Program Files\MATLAB\R2018a
MATLAB Version : 9.4.0.813654 (R2018a)
OpenGL : hardware
Operating System : Microsoft Windows 10 Home Single Language
Process ID : 168
Processor ID : x86 Family 6 Model 78 Stepping 3, GenuineIntel
Session Key : c79f6641-2f0d-4074-aa5c-b9954637c6c3
Window System : Version 10.0 (Build 17134)</p><p>Fault Count: 1</p><p>Abnormal termination</p><p>Register State (from fault):
RAX = 0000000000000000 RBX = 00000000f693b430
RCX = 00000000f693b430 RDX = 00000001243c46d0
RSP = 00000001243c4310 RBP = 00000001243c4410
RSI = 00000000f693b430 RDI = 0000000000000000</p><pre> R8 = 00000000044abde4 R9 = 000000000000001b
R10 = 00000000000001c8 R11 = 00000001243c45c0
R12 = 00007ff974c986a4 R13 = 00000000ffffffff
R14 = 00000000c76b47f0 R15 = 00000001243c46d0</pre><pre class="language-matlab">RIP = 000000013d3521de EFL = 00010202
</pre><pre> CS = 0033 FS = 0053 GS = 002b</pre><p>Stack Trace (from fault):
[ 0] 0x000000013d3521de C:\WINDOWS\System32\DriverStore\FileRepository\c0313191.inf_amd64_f86a31122289b968\atio6axx.dll+16261598 DrvPresentBuffers+14713566
[ 1] 0x000000013d3521a6 C:\WINDOWS\System32\DriverStore\FileRepository\c0313191.inf_amd64_f86a31122289b968\atio6axx.dll+16261542 DrvPresentBuffers+14713510
[ 2] 0x000000013c64fedd C:\WINDOWS\System32\DriverStore\FileRepository\c0313191.inf_amd64_f86a31122289b968\atio6axx.dll+02621149 DrvPresentBuffers+01073117
[ 3] 0x000000013d1bd271 C:\WINDOWS\System32\DriverStore\FileRepository\c0313191.inf_amd64_f86a31122289b968\atio6axx.dll+14602865 DrvPresentBuffers+13054833
[ 4] 0x000000013d1bd448 C:\WINDOWS\System32\DriverStore\FileRepository\c0313191.inf_amd64_f86a31122289b968\atio6axx.dll+14603336 DrvPresentBuffers+13055304
[ 5] 0x000000013d1bce68 C:\WINDOWS\System32\DriverStore\FileRepository\c0313191.inf_amd64_f86a31122289b968\atio6axx.dll+14601832 DrvPresentBuffers+13053800
[ 6] 0x000000013c52194b C:\WINDOWS\System32\DriverStore\FileRepository\c0313191.inf_amd64_f86a31122289b968\atio6axx.dll+01382731 DrvSwapBuffers+00000779
[ 7] 0x000000013c520c77 C:\WINDOWS\System32\DriverStore\FileRepository\c0313191.inf_amd64_f86a31122289b968\atio6axx.dll+01379447 DrvValidateVersion+00000055
[ 8] 0x00007ff9704d6cfc C:\WINDOWS\system32\opengl32.dll+00158972 wglSwapMultipleBuffers+00006188
[ 9] 0x00007ff9704d710d C:\WINDOWS\system32\opengl32.dll+00160013 wglSwapMultipleBuffers+00007229
[ 10] 0x00007ff9704ea209 C:\WINDOWS\system32\opengl32.dll+00238089 wglDescribePixelFormat+00000313
[ 11] 0x00007ff9704e95d5 C:\WINDOWS\system32\opengl32.dll+00234965 wglChoosePixelFormat+00000133
[ 12] 0x00007ff9940a7979 C:\WINDOWS\System32\gdi32full.dll+00424313 ChoosePixelFormat+00000057
[ 13] 0x00007ff952c3c1eb C:\Program Files\MATLAB\R2018a\bin\win64\platforms\qwindows.dll+00246251
[ 14] 0x00007ff952c3c2d1 C:\Program Files\MATLAB\R2018a\bin\win64\platforms\qwindows.dll+00246481
[ 15] 0x00007ff952c39f76 C:\Program Files\MATLAB\R2018a\bin\win64\platforms\qwindows.dll+00237430
[ 16] 0x00007ff952c3bc7f C:\Program Files\MATLAB\R2018a\bin\win64\platforms\qwindows.dll+00244863
[ 17] 0x00007ff952c0b0d2 C:\Program Files\MATLAB\R2018a\bin\win64\platforms\qwindows.dll+00045266
[ 18] 0x00007ff952c0a24c C:\Program Files\MATLAB\R2018a\bin\win64\platforms\qwindows.dll+00041548
[ 19] 0x00007ff94367b090 C:\Program Files\MATLAB\R2018a\bin\win64\Qt5GuiMW.dll+00372880 MW_QT::QOpenGLContext::create+00000048
[ 20] 0x00007ff9601eb49f C:\Program Files\MATLAB\R2018a\bin\win64\Qt5WebEngineMW.dll+00046239 MW_QT::QtWebEngine::initialize+00000287
[ 21] 0x00000000ec2fd3fe C:\Program Files\MATLAB\R2018a\bin\win64\Qt5CoreMW.dll+01758206 MW_QT::qt_call_post_routines+00000382
[ 22] 0x00000000ec2fba8f C:\Program Files\MATLAB\R2018a\bin\win64\Qt5CoreMW.dll+01751695 MW_QT::QCoreApplicationPrivate::init+00000367
[ 23] 0x00007ff94364acd9 C:\Program Files\MATLAB\R2018a\bin\win64\Qt5GuiMW.dll+00175321 MW_QT::QGuiApplicationPrivate::init+00000041
[ 24] 0x00000000ec83244f C:\Program Files\MATLAB\R2018a\bin\win64\Qt5WidgetsMW.dll+00074831 MW_QT::QApplicationPrivate::init+00000015
[ 25] 0x00000000ec82e63b C:\Program Files\MATLAB\R2018a\bin\win64\Qt5WidgetsMW.dll+00058939 MW_QT::QApplication::QApplication+00000091
[ 26] 0x00000000eace95ae bin\win64\glee.dll+00693678 GLIMReentrancyProtector::GLIMReentrancyProtector+00000126
[ 27] 0x00000000ead56939 bin\win64\glee.dll+01141049 GuiObject::scheduleDelete+00094041
[ 28] 0x00000000ead56075 bin\win64\glee.dll+01138805 GuiObject::scheduleDelete+00091797
[ 29] 0x00000000ead55b09 bin\win64\glee.dll+01137417 GuiObject::scheduleDelete+00090409
[ 30] 0x00007ff9935ac1ae C:\WINDOWS\System32\ucrtbase.dll+00115118 o_strcat_s+00000094
[ 31] 0x00007ff996e63034 C:\WINDOWS\System32\KERNEL32.DLL+00077876 BaseThreadInitThunk+00000020
[ 32] 0x00007ff996fb1431 C:\WINDOWS\SYSTEM32\ntdll.dll+00463921 RtlUserThreadStart+00000033</p>ADITYA PARHADhttps://ww2.mathworks.cn/matlabcentral/profile/authors/7299088-aditya-parhadtag:ww2.mathworks.cn,2005:Question/4070302018-06-23T04:48:24Z2018-06-23T04:48:24ZHow to optimize code for GPU and remove for loops?<p>Hello,
I am trying to optimize this code for GPU in order to speed up calculations. Here is small data sample, but mine data is quite big (1000000x100) and there can be a number of this size arrays. I was trying to use arrayfun but due to indexing it was not an option. 3D arrays were used as well with no luck to achieve my goal. The idea of code is to eliminate pair duplicates. Here is sample for, which due to for loops and other is very slow for big data:</p><pre> x1=[2 1 4 5 3;5 2 3 3 4;5 4 1 1 2;3 5 1 4 2;3 3 2 1 2];
idx1=[1 1 0 0 1;1 1 1 0 0;1 1 0 1 1;1 0 1 1 1;1 1 1 1 1];
idx=gpuArray(idx1);
x=gpuArray(x1);
[n1 n2]=size(x);
for i=1:n1
c(i,:)=x(i,x(i,:));
end
for j=1:n1
idx2(j)={find(idx(j,:)>0)};
tempIdx=ones(size(idx(j,:)));
idx3(j)={find(idx(j,:)>0)};
for i=1:n2
if(i==c(j,i))
if any(c(j,i)==idx2{j})
if tempIdx(c(j,i)==idx2{j})==1
idx2{j}(c(j,i)==idx2{j})=NaN;
tempIdx(x(j,i))=0;
end
end
end
end</pre><p>end</p><p>Array x represents pairs and array idx represents the invoking of pair.</p>Mantas Vaitonishttps://ww2.mathworks.cn/matlabcentral/profile/authors/4645656-mantas-vaitonistag:ww2.mathworks.cn,2005:Question/3938502018-04-10T08:07:50Z2018-06-23T04:46:52Zconvert struct2mat<p>I have a struct.I want convert this struct to matrix. I used the 'cell2mat( struct2cell( YourStructure ) )' command and I got that error (Error using class
Not enough input arguments.). My struct name is 'class'.I used this cell2mat(struct2cell(class)).</p>z donyavihttps://ww2.mathworks.cn/matlabcentral/profile/authors/9239590-z-donyavitag:ww2.mathworks.cn,2005:Question/2924462016-06-27T08:30:00Z2018-06-23T04:43:00ZIEEE 118 bus system<p>Hi, I am trying to simulate IEEE 118 bus system in simulink. I have the transmission line data in per unit ( R,X,B). In simulink the pi section block asks for positive, zero and negative components. how do I get these values?</p>Nithin Shttps://ww2.mathworks.cn/matlabcentral/profile/authors/7653249-nithin-stag:ww2.mathworks.cn,2005:Question/4070292018-06-23T04:39:56Z2018-06-23T04:39:56Z3D plotting of equation<p>Hi! I need to plot such an equation (function) in 3D space:
2*x^2+1.5*x*y-.8*x*z+2.5*y^2-3*y*z+z^2-0.35=0.
Everything that I have found, the function is f(x,y,z)=... or f(x,y)=... .
I tried to use v=2*x^2+1.5*x*y-.8*x*z+2.5*y^2-3*y*z+z^2;
scatter3(x(:), y(:), z(:), [], v(:));
and slice v=0.35, but turns out only x, y and z could be sliced.
Thank you very much in advance.</p>samira karimihttps://ww2.mathworks.cn/matlabcentral/profile/authors/9264838-samira-karimitag:ww2.mathworks.cn,2005:Question/4068642018-06-21T21:36:57Z2018-06-23T04:15:18ZHow do I sum over one dimension of a multidimensional array?<p>I have four dimensions in a netcdf file: lat, long, sector and time. I want to sum over JUST sector. Is there a simple command to do this?</p>Nesha Wrighthttps://ww2.mathworks.cn/matlabcentral/profile/authors/10983406-nesha-wrighttag:ww2.mathworks.cn,2005:Question/1424502014-07-18T20:08:14Z2018-06-23T04:05:36ZHow to convert a voltage source into current course in simulink<p>Hello All,
I was working on a power system which has three phase voltage sources and some transformers and loads. Now, I'm trying to replace a voltage source with a steam turbine & governor generator model but when i try to run this, it will say</p><p>_"The following two blocks cannot be connected in series:</p><p>Block 1: 'A: Subsystem1/Synchronous Machine pu Standard'
Block 2: 'phase_A: Branch-2-4'</p><p>The first block, modeled as a current source, cannot be connected in series with the inductive element of the second block.
Add a high-value resistance in parallel with one of the two block.
You can also specify high-value resistive snubbers if the blocks have a snubber device."_</p><p>can you help me out what is the actual problem.</p><p>thank you in advance.</p>Ranganath Vallakatihttps://ww2.mathworks.cn/matlabcentral/profile/authors/4682624-ranganath-vallakatitag:ww2.mathworks.cn,2005:Question/4067052018-06-21T07:01:02Z2018-06-23T03:57:11ZHow to make equal number of images in each class.? which is the best method for this.<p>Say i have different classes of images, but they are not equal in number to train. some class of images are in 1000's, some are in 100's, some are below 50 and 10. How i can make them equal.? Which is the best method for this.After that i need to do feature extraction. So if i have good number of images in each class i can train well i guess.</p>karthik khttps://ww2.mathworks.cn/matlabcentral/profile/authors/11636146-karthik-ktag:ww2.mathworks.cn,2005:Question/868342013-09-10T21:40:14Z2018-06-23T03:54:38ZHow do i run my simulink fast?<p>I have four different models name 1) wind.slx 2)steam.slx 3)fuel.slx 4)pvpanel
all are running good. but when i combine all fourin one model name power.slx the power.slx run very very slow. I want to speed up my simulink.
i am using ode23tb for all 4 files.
Is there any way to run all 4 files parallel and get result on other model</p><p>I am using this model
1)wind <a href = "http://www.mathworks.com/help/physmod/powersys/examples/wind-turbine-asynchronous-generator-in-isolated-network.html">http://www.mathworks.com/help/physmod/powersys/examples/wind-turbine-asynchronous-generator-in-isolated-network.html</a></p><p>2)phot voltic cell <a href = "http://www.mathworks.com/matlabcentral/fileexchange/41537-a-photovoltaic-panel-model-in-matlabsimulink">http://www.mathworks.com/matlabcentral/fileexchange/41537-a-photovoltaic-panel-model-in-matlabsimulink</a></p><p>3)Fuell cell <a href = "http://www.mathworks.com/help/physmod/powersys/examples/6-kw-45-vdc-fuel-cell-stack.html">http://www.mathworks.com/help/physmod/powersys/examples/6-kw-45-vdc-fuel-cell-stack.html</a></p><p>4) steam turbine <a href = "http://www.mathworks.com/help/physmod/powersys/examples/steam-turbine-and-governor-system-subsynchronous-resonance.html">http://www.mathworks.com/help/physmod/powersys/examples/steam-turbine-and-governor-system-subsynchronous-resonance.html</a></p><p>I am using all 4 models in one model name Power.slx . I am using some additional things like universal bridge , PWM, transformers, Batteries.
above four files are running good but. power.slx time is 3.64e-16
so simulation is very very slow. I want to speed up simulation. kindly help me out.</p>zainhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4438003-zaintag:ww2.mathworks.cn,2005:Question/4058042018-06-15T06:40:57Z2018-06-23T03:40:57ZHello everyone, I am stuck in a question. Can anyone there help me out? The question is as follows-<p>I have a 3D matrix in which each 2D submatrix is of size 7×4.I have to randomly select any 4 out of these 7 rows(for various 3D indexes) except 1 row which will be decided by user input.That means, I can't select that particular row while selecting 4 rows.
Thanks in advance.</p>SUDIPTA MUKHERJEEhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12594000-sudipta-mukherjeetag:ww2.mathworks.cn,2005:Question/4070262018-06-23T03:38:16Z2018-06-23T03:38:16ZI want to put this equation in MATLAB and write a report about it, I will need at least one graph, can anyone please give me with the code to do so?<p>2(y-1)y’ = 3t^2 + 4x + 2, y(0)= -1</p>Brian Kenorhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13024197-brian-kenortag:ww2.mathworks.cn,2005:Question/4070252018-06-23T03:35:29Z2018-06-23T03:35:29ZPlotting a graph by inputting the equation and assigning the variables for the y and x axis<p>How do I plot the following equation with log(y) as the y-axis and log(x) as the x-axis?</p><p>-709868=2*(1873)*(8.3144)*(5.3*x-433*y)+3*(1873)*(8.3144)*(-13.193*y-433*x)+2*(1873)*(8.3144)*log(x)+3*(1873)*(8.3144)*log(y)+3*(1873)*(8.3144)*log(100*16/55.85)+2*(1873)*(8.3144)*(-2.86)</p>AtlasTobiashttps://ww2.mathworks.cn/matlabcentral/profile/authors/10492536-atlastobiastag:ww2.mathworks.cn,2005:Question/4070242018-06-23T03:14:57Z2018-06-23T03:14:57ZWhat its defined in MCR CACHE Root?<p>bellow MCR CACHE Root its a Temp file stay time or what ? can any share idea's ?</p>Selva Karnahttps://ww2.mathworks.cn/matlabcentral/profile/authors/4733665-selva-karnatag:ww2.mathworks.cn,2005:Question/4069892018-06-22T18:00:01Z2018-06-23T02:52:51ZScanning background noise filtering<img src = "/matlabcentral/answers/uploaded_files/122465/jpg1.jpg"><p>Hello everybody. I am an absolutly newbie at mathlab.</p><p>I am looking for a way for removal scanning background noise for this kind of noise.</p><p>I have found some works titled "Marginal noise removal of document images", but dont know how to performe it at matlab.</p><p>I'm attaching an example of the scanning background noise talking about.</p><p>The background noise is basically at the top of the scanned image.</p><p>Thanks!</p>Wilbert Vonhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12825113-wilbert-vontag:ww2.mathworks.cn,2005:Question/4070232018-06-23T02:09:43Z2018-06-23T02:09:43ZPython scripts with numpy don't work when called from MATLAB<p>Hi,</p><p>I'm trying to call a python script I've written, from within my MATLAB code.
I'm having a problem where I can't call any scripts that import numpy.</p><p>For example, the following file (abc.py) works without any issues:</p><pre class="language-matlab">def foo():
return 55
</pre><p>but if I add the import statement, it ceases to work.</p><pre class="language-matlab">import numpy as np
</pre><pre class="language-matlab">def foo():
return 55
</pre><p>The MATLAB error I get is</p><pre class="language-matlab">Undefined variable "py" or class "py.abc.foo".
</pre><p>Does anyone have any idea on how to fix this? I'm running the latest version of Anaconda for my python.</p>AShttps://ww2.mathworks.cn/matlabcentral/profile/authors/9148483-astag:ww2.mathworks.cn,2005:Question/4068022018-06-21T15:41:54Z2018-06-23T02:04:46ZHow to clear the checkbox using commands?<p>How can I uncheck this checkbox "Limit the maximum array size to a percentage of RAM" ?</p><img src = "/matlabcentral/answers/uploaded_files/122275/KakaoTalk_20180621_114024497.jpg">Kwonsik Songhttps://ww2.mathworks.cn/matlabcentral/profile/authors/11893298-kwonsik-songtag:ww2.mathworks.cn,2005:Question/4068892018-06-22T04:46:28Z2018-06-23T01:13:34ZHow to feed data from javascript to matlab ?<p>I want to get data from JavaScript into MATLAB</p>Sourav Mondalhttps://ww2.mathworks.cn/matlabcentral/profile/authors/10781916-sourav-mondaltag:ww2.mathworks.cn,2005:Question/4070222018-06-23T01:05:05Z2018-06-23T01:05:05ZAdvice on when to start writing custom CUDA <p>Hello all,
I currently take advantage of a lot of Matlab's GPU enabled functions (matrix operations, FFTs, etc.) which provide great speed advantages over their CPU counterparts. I thought GPU matrix operations were fast...until I discovered a <a href = "https://www.mathworks.com/help/distcomp/examples/accessing-advanced-cuda-features-using-mex.html">CPU/GPU/MEX-CUDA comparison for running Conway's game of life</a>. On my machine, the MEX-CUDA version was ~50X faster than the GPU version. Or, using the CPU as a comparison</p><ul><li>CPU - 1X</li><li>GPU - 7X</li><li>MEX-CUDA - 350X</li></ul><p>So, with those kind of speed gains, I am finally feeling motivated to learn some CUDA. However, what is not clear to me is: When is there a significant speed advantage in writing one's own CUDA kernel? There several narrower questions:</p><ol><li>I use GPU > CPU when I can frame an operation as a binary array operation (matrix additions and the like, NOT sorts). If I meet this criterion, is there a second criterion that says I should write my own CUDA code rather than doing everything inside Matlab and leveraging the built-in GPU enabled functions using e.g. arrayfuns?</li><li>I <b>assume</b> that the GPU enabled functions for Matlab, like fft, interp1 (with a linear interpolant), exp, etc. are all already as accelerated as they get: I could not write a faster fft myself. Instead, it must be other problems that can be framed as binary array operations (like the stencil problem from the Life example) that would require special treatment. Is this true?</li></ol><p>Finally, if someone has a nice starting place for CUDA with Matlab, I would appreciate the link; I know a bit of C, but the example files in the Life tutorial, such as pctdemo_life_mex_shmem.cu, are a little outside of my current skill set.</p><p>Cheers, Dan</p>Daniel Plotnickhttps://ww2.mathworks.cn/matlabcentral/profile/authors/7040802-daniel-plotnicktag:ww2.mathworks.cn,2005:Question/4067322018-06-21T10:19:44Z2018-06-23T00:59:48ZHow it is possible to change all images orientation to same i.e. to vertical <p>My folder consisting of 1000 binary images with different orientation. I want to make all of them to vertically align. How it will be possible through a single code ? Later I want to save all the vertically aligned images to a new folder.
Note:few images are already in vertical orientation . I want to keep them as it is .</p>Zara Khanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/10893209-zara-khantag:ww2.mathworks.cn,2005:Question/4070212018-06-23T00:57:31Z2018-06-23T00:57:31ZUsing the same Matlab license in two countries<p>When I try to purchase a license for Matlab, it says in fine print that it is intended for purchase and use in my current region. However, I will be studying in another country starting this Fall and would like to continue using Matlab. Can I purchase a license for Matlab in one region and continue to use it in another region?</p>Yurim Leehttps://ww2.mathworks.cn/matlabcentral/profile/authors/7218190-yurim-leetag:ww2.mathworks.cn,2005:Question/4069862018-06-22T17:37:14Z2018-06-23T00:54:39ZExtract indices of two related arrays based on uniqueness and minimum WITHOUT FOR LOOP<p>I have two arrays, A and B, whose indices relate to inputs of an analysis (i.e. A(1) and B(1) are two tracked outputs of run 1 of a simulation with distinct inputs, A(7) and B(7) correspond to the 7th run, whose inputs vary from all other runs).</p><pre class="language-matlab">A B
0.5 1
0.75 1
0.75 3
1 7
0.5 4
0.75 9
1 2
1 6
0.5 1
</pre><p>I am trying to create a vector of indices which tracks all minimum values of B for each unique value of A
So from the above example the desired output is</p><pre class="language-matlab">index
1
2
8
10
</pre><p>*Note that if there are multiple indices which have the minimum value of B for the same value of A, i want to keep both indices.</p><p>I am currently using a for loop (below), but because my array A and B are extremely large (1*10^8 entries) it take hours to run the script</p><pre> %Extract unique elements of A
Unique_A = unique(A);
%preallocate index vector for speed (no clue how big this will be so intentionally large
Alternative_index = zeros(1*10^6,1);</pre><pre> for i = 1:length(Unique_A)
% Find the indices of the Benefit vector which correspond to a each unique value of A
indices = find(A==Unique_A(i));
%Now determine which of the corresponding indices in B are equal to the minimum value
min_B_indices = (indices(B(indices)== min(B(indices))))
%since the index vector was pre allocated, I need to make sure I am appending the vector without overwriting entries. So determine how many entries will need to be appended:
length_of_append = length(min_B_indices)
%Now find the first zero element of the preallocated vector
first_zero = find(Alternative_index==0, 1, 'first')
%Now add the indices to the preallocated vector
Alternative_index(first_zero:first_zero+length_of_append-1,1) = min_B_indices;</pre><pre> end
%remove trailing zeros
Alternative_index = Alternative_index(Alternative_index~=0);</pre><p>I have wracked my brain on how to do this without a for loop...anyone have a suggestion?</p>Still Learning Matlabhttps://ww2.mathworks.cn/matlabcentral/profile/authors/6833272-still-learning-matlabtag:ww2.mathworks.cn,2005:Question/4066212018-06-20T17:31:26Z2018-06-23T00:54:28Zode45 System of Equations Difficulties - Launch Vehicle Simulation<p>I am attempting to solve a system of ODEs that describe a shuttle launch. The calculation incorporates time-dependent unit step functions with differential equations to describe launch kinematics with realistic engine burn and thrust vectoring profiles.</p><p>I am using <a href = "https://www.cengage.com/math/book_content/0495011592_giordano/student_cd/ilaps/launch_shuttle.pdf">this document</a> for reference, trying to recreate the results presented on pages 24 - 25 ('Requirement 15') of the PDF which were originally computed in Mathematica using the NDSolve[] functionality. I have successfully recreated the results from Part I and Part II of the document but have encountered a lot of difficulty in Part III. For this system of equations, the output from 'ode45' will output the following warning if a 'NonNegative' argument is not included in 'odeset':</p><pre class="language-matlab">'Warning: Failure at t=5.106812e+01. Unable to meet integration tolerances without reducing the step size below the smallest value
allowed (1.136868e-13) at time t.'
</pre><p>If a 'NonNegative' argument is provided, the solution covers the given 'tspan' but is incorrect according to the reference document. The 4th and 5th index output values have the correct shape over time but incorrect values. I am to the point where I cannot determine the origin of the errors; I believe the system of equations and the time-dependent unit step functions are defined correctly within the context of 'ode45' but I cannot justify the rationale behind the use of the 'NonNegative' specifier. When plotted using a time vector the non-DE unit step functions ('SRBT' and 'MET') look correct compared to the reference PDF. My code is as follows:</p><pre class="language-matlab">%% Requirement 15
</pre><pre class="language-matlab">R = 20.9e6; %earth radius in ft
g = 32.174; %gravitational acceleration in ft/s^2
</pre><pre class="language-matlab">tspan = [0 720];
y0 = [R 0 0 1530 4.5e6/g];
</pre><pre class="language-matlab">opts = odeset('NonNegative',[2 3 4 5]);
</pre><pre class="language-matlab">[T,Y] = ode45(@(t,y) myode(t, y), tspan, y0, opts);
</pre><pre class="language-matlab">function dydt = myode(t, y)
</pre><pre class="language-matlab">R = 20.9e6; %earth radius in ft
g = 32.174; %gravitational acceleration in ft/s^2
</pre><pre class="language-matlab">% Define Heaviside step function
hvsd = @(x) [1*(x == 0) + (x > 0)];
</pre><pre class="language-matlab">%Fuel rate - Main Engines
frMET = 117.9; %slugs/s
</pre><pre class="language-matlab">%Fuel rate - Solid Rocket Boosters
frSRB = 94.7; %slugs/s
</pre><pre class="language-matlab">% Mass of SRBs
mSRB = 2*6250; %slugs
</pre><pre class="language-matlab">% External tank mass
mEXT = 2062; %slugs
</pre><pre class="language-matlab">% SRB Thrust Schedule
SRBT = ((6.6 - 2.2.*(t/50)).*(hvsd(t) - hvsd(t-50)) +...
4.4.*(hvsd(t-50) - hvsd(t-120)));
</pre><pre class="language-matlab">% ME Thrust Schedule
MET = (1.125.*(hvsd(t) - hvsd(t-26) + 0.95.*(hvsd(t-26) - hvsd(t-60))) +...
1.125.*(hvsd(t-60) - hvsd(t-460)) + 0.731.*(hvsd(t-460) - hvsd(t-480)));
</pre><pre class="language-matlab">% Thrust Vector Control
alpha = 90.*(hvsd(t) - hvsd(t - 6)) +...
(90-(12.*((t - 6)./20))).*(hvsd(t - 6)- hvsd(t - 26))+...
(78-(57.*((t - 26)./214))).*(hvsd(t - 26)- hvsd(t - 240)) + atand(y(2)/y(4))*hvsd(t - 240);
</pre><pre class="language-matlab">% Drag Coefficient
D = 430*(2.33e-3)*exp(-(y(1) - R)/28276)*(y(2)^2 + (y(4) - 1530)^2);
</pre><pre class="language-matlab">dy1 = y(2);
dy2 = y(4)^2/y(1) - g*(R/y(1))^2 + (1/y(5))*((SRBT + MET)*(1.25 - 0.25*exp(-(y(1) - R)/28276)) - D)*sind(alpha);
dy3 = y(4)/y(1);
dy4 = (y(2)*y(4))/y(1) + (1/y(5))*((SRBT + MET)*(1.25 - 0.25*exp(-(y(1) - R)/28276)) - D)*cosd(alpha);
</pre><pre class="language-matlab">dy5 = -frMET.*MET - frSRB.*SRBT - mSRB.*(hvsd(t - 119.5) - hvsd(t - 120.5)) - ...
mEXT.*(hvsd(t - 479.5) - hvsd(t - 480.5));
</pre><pre class="language-matlab">dydt = [dy1 dy2 dy3 dy4 dy5]';
</pre><pre class="language-matlab">end
</pre><p>Any input regarding the mechanics of the 'NonNegative' specifier or correct implementation of time-dependent unit step functions would be appreciated. My objective is to achieve matching results with the PDF document.</p><p>Thanks!</p>JThttps://ww2.mathworks.cn/matlabcentral/profile/authors/13044728-jttag:ww2.mathworks.cn,2005:Question/4062042018-06-18T17:29:40Z2018-06-23T00:46:39ZMaximizing code interpretability while minimizing computational cost. <p>Hello,
I have a question about whether there is a current method to maximize code readability while minimizing computational complexity.</p><p>For example, the code:</p><pre> Th = atan(x./y);</pre><p>is slower than</p><pre> x = atan(x./y); </pre><p>Provided that you do not need to retain the variable x, this method is faster ( <a href = "https://www.mathworks.com/company/newsletters/articles/programming-patterns-maximizing-code-performance-by-optimizing-memory-access.html">due to memory access issues as far as I understand</a> ). In addition, if the memory footprint of variables is a concern, this will simply overwrite the values of x rather than creating a new variable to occupy memory.</p><p>However, the latter method reduces code interpretability by obscuring the fact that, in this example, I am clearly changing to an angle using the tangent function. So, how do I balance these two apparently competing issues?</p><p>So far I have come up with four options:</p><p>For the generic operation</p><pre> newVar = myFun(oldVar)</pre><p>where newVar operates in the same way as oldVar = myFun(oldVar), but with a new name</p><p>(1) Rename the variable using intermediaries. Maybe using oldVar = myFun(oldVar); newVar = oldVar; clear oldVar; However, this lacks a certain amount of elligence and just does not sit well with me. Maybe it is the only way.</p><p>(2) Rename the variable directly. I think this gets me in hot water with the 'no dynamic variable names' credo, if it's even possible, but there is a 'rename variable' option within the workspace pane. However, even if there is a mechanism to rename the variable, similarly to the above idea it also does not necessarily increase code
interpretability/compactness.</p><p>(3) Create a custom class so that the variables are handles referencing the same object in memory. oldVar and newVar point to the same object in the same way that newVar = oldVar does not create a new copy in memory until newVar is modified. Drawback: I think that will ruin a lot of codes that utilize class requirements, such as requiring inputs be 'double'. I also do not know if this will actually reduce memory loading, as I am still a novice at handle objects vs. data objects.</p><p>(4) Implement a 'description' for each variable. This does not currently exist, afaik, but would be useful more generically. If there is an initial description of 'x' that is 'distance' and then after x=atan(x) you can change the description to 'angle', that would extremely helpful for many applications. This could also be used for storing units (distance in feet vs. distance in meters). I could see creating custom classes that include descriptions in their properties, but again I think this would break class requirements for many standard functions. Maybe make them a child of the class 'double'?</p><p>(5) Suck it up and do it all with code comments.</p><p>(6) Magic, or programming tricks significantly advanced as to be indistinguishable from magic.</p><p>========TLDR=======</p><p>How do I maximize code interpretability while minimizing memory/computational cost for operations of the form
x = fun(x) VS. y = fun(x).</p><p>Cheers,
Dan</p><p>PS. Below is a code that lets you see the <i>slight</i> speed advantage to writing to the same variable. Of bigger concern to me is the memory footprint. This is taken from the article linked above and <a href = "https://www.mathworks.com/company/newsletters/articles/programming-patterns-maximizing-code-performance-by-optimizing-memory-access.html">here</a> .</p><pre> N = 3e3;
x = randn(N);
tic
y = x*1.2;
toc
tic
x = x*1.2;
toc</pre>Daniel Plotnickhttps://ww2.mathworks.cn/matlabcentral/profile/authors/7040802-daniel-plotnicktag:ww2.mathworks.cn,2005:Question/4070112018-06-22T22:05:29Z2018-06-23T00:34:14ZHow to omit matrix elements not satisfying a particular constraint? <p>Supposing I have a matrix A, with size 400 x 300 x 1600. I am having some constraint. An now I want to omit those elements not satisfying the constraint, and form a matrix of new dimension.</p>Abhishek Singhhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12066903-abhishek-singhtag:ww2.mathworks.cn,2005:Question/4067942018-06-21T15:02:19Z2018-06-23T00:25:21ZHow to choose a random value from an array?<p>I have a matrix</p><pre> A= [2846 2402 2374 209
54 46 45 4
35 70 35 35
2 2 2 2
2 4 10 12]</pre><p>I want to select a random element among the values which are lower than 50 from the third row, in other words, one of the 35s. I also want to obtain the column number of the value that i have selected. Couldn't find a decent way to do it.</p>ozan aksuhttps://ww2.mathworks.cn/matlabcentral/profile/authors/8884702-ozan-aksutag:ww2.mathworks.cn,2005:Question/4070182018-06-23T00:11:30Z2018-06-23T00:11:30ZHow do I use MatLab to loop through many folders and extract columns of data from .txt files in those folders?<p>I have a directory that includes 30 folders that all contain a different number of .txt files. Each folder is a different wind tunnel run and each .txt is a point in that run, and every point has several hundred rows and a certain number of columns for pressure, dB, kts, etc.</p><p>I need to build a loop that will go through each folder and each .txt to extract the data from specific columns within the .txt so I can perform calculations with them.</p><p>I also want to produce a table that compares run #'s and pressures, but once I extract the data I should be able to figure that out.</p><p>Thank you!</p>Lucia Langhttps://ww2.mathworks.cn/matlabcentral/profile/authors/8560942-lucia-langtag:ww2.mathworks.cn,2005:Question/3971912018-04-25T03:56:10Z2018-06-23T00:10:19ZConcatenation of columns of several cell Arrays<p>I am trying to concatenate several columns of one cell array with several columns of another cell array.</p><p>I have A = 6xn, where n can be any number between 1&9.</p><p>I have B = 6xm,where m can be any number between 1&9</p><p>I need to create a cell array C = 6x1</p><p>For example:</p><pre class="language-matlab">A =
472x2 double 471x2 double 488x2 double 496x2 double 494x2 double 495x2 double
472x2 double 471x2 double 488x2 double 496x2 double 494x2 double 495x2 double
472x2 double 471x2 double 488x2 double 496x2 double 494x2 double 495x2 double
472x2 double 471x2 double 488x2 double 496x2 double 494x2 double 495x2 double
472x2 double 471x2 double 488x2 double 496x2 double 494x2 double 495x2 double
472x2 double 471x2 double 488x2 double 496x2 double 494x2 double 495x2 double
</pre><pre class="language-matlab">B=
</pre><pre class="language-matlab">460x2 double 509x2 double 503x2 double 503x2 double 488x2 double 490x2 double 488x2 double 503x2 double 518x2 double
460x2 double 509x2 double 503x2 double 503x2 double 488x2 double 490x2 double 488x2 double 503x2 double 518x2 double
460x2 double 509x2 double 503x2 double 503x2 double 488x2 double 490x2 double 488x2 double 503x2 double 518x2 double
460x2 double 509x2 double 503x2 double 503x2 double 488x2 double 490x2 double 488x2 double 503x2 double 518x2 double
460x2 double 509x2 double 503x2 double 503x2 double 488x2 double 490x2 double 488x2 double 503x2 double 518x2 double
460x2 double 509x2 double 503x2 double 503x2 double 488x2 double 490x2 double 488x2 double 503x2 double 518x2 double
</pre><p>The result, for each row, of concatenating all columns of A and the first 4 columns of B will be:</p><pre class="language-matlab">C=
4891x2 double
4891x2 double
4891x2 double
4891x2 double
4891x2 double
4891x2 double
</pre><p>I can concatenate all columns of A for each row with:</p><pre class="language-matlab">for i=1:6
C{i,1}=cat(1, A{i,:});
end
</pre><p>I want to avoid several for loops and the creation of intermediate variables, so I tried:</p><pre> for i=1:6
C{i,1}=cat(1, A{i,:}, B(i,[1:num_extra_trials_w]));end</pre><pre class="language-matlab">for i=1:6
C{i,1}=cat(1, A{i,:}, cat(1,B(i,[1:num_extra_trials_w])));end
</pre><pre class="language-matlab">for i=1:6
C{i,1}=cat(1, A{i,:}, {cat(1,B(i,[1:num_extra_trials_w]))});end
</pre><p>But none are creating a 6x1 cell array with 4891x2 double in each.
What would be the proper syntax?</p><p>Thank you for your help!</p>ErikaZhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4536604-erikaztag:ww2.mathworks.cn,2005:Question/4070172018-06-22T23:52:54Z2018-06-22T23:52:54ZMY GUI work for some kind of excel sheet with small data, but for sheet with big data while generating plot it shows this error message? vector length is not same, Although it is same<pre> using plot
Vectors must be the same length.</pre><p>Error in untitled5050>pushbutton2_Callback (line 108)
plot(handles.axes1, l,x)</p><p>Error in gui_mainfcn (line 95)
feval(varargin{:});</p><p>Error in untitled5050 (line 42)
gui_mainfcn(gui_State, varargin{:});</p><p>Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)untitled5050('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.</p><p>>></p>Juned Khakhihttps://ww2.mathworks.cn/matlabcentral/profile/authors/12490913-juned-khakhitag:ww2.mathworks.cn,2005:Question/4068442018-06-21T19:59:21Z2018-06-22T23:50:52ZTry to do a curve fitting on a komplex alternating function <img src = "/matlabcentral/answers/uploaded_files/122313/Unbenannt.JPG"><p>Dear community members,</p><p>i try to do a curve fitting on this komplex function. I wasn't successful with "polyfit" and "ezyfit". Is there any possibility?</p><p>Thanks for your help!
Max</p>Max Weberhttps://ww2.mathworks.cn/matlabcentral/profile/authors/11855743-max-webertag:ww2.mathworks.cn,2005:Question/4070032018-06-22T20:50:47Z2018-06-22T23:48:30ZCan't replace the existing struct in a Mat file<p>I am working on a project and have saved many data along the way in a Mat file which is like a database for me. However, starting from yesterday, I have difficulty changing the values of existing struct variables in the Mat file which is currently less than 600MB in size.Detailed structure of the Mat file is at the bottom.</p><p>In my codes, I use</p><pre class="language-matlab">mReadable = matfile(datafullfile, 'Writable',true);
</pre><p>so that I don't have to load all of Mat file variables and
I have been able to rewrite the variables in the Mat file after making changes by using the following command.</p><pre class="language-matlab">save( datafullfile, 'payoff52', '-append');
</pre><p>However, I can't do that for some variables any longer since yesterday. So I have to save them with a new name to the Mat file. For
example, the payoff52 and the IUpayoff both have versions there.</p><p>datafullfile is the full path+fileName.</p><pre class="language-matlab">save( datafullfile, 'payoff52', '-append');
Error using save
Can not write file G:\Pm\**\***Data.mat.
</pre><p>Any suggestions? I don't want to keep adding versions of a variable. Thanks!</p><pre class="language-matlab">Name Size Bytes Class Attributes
</pre><pre> B10YrSpd - 14346 fints
B10YrSpd_M 1x1 28166 struct
B10YrSpd_MA 1x1 19628664 struct
CopModel 1x1 57614964 struct
IU_Sim 1x1 191082104 struct
IU_Sim_Scn 1x1 378620624 struct
IUpayoff 1x1 13072 struct
IUpayoff01 1x1 13072 struct
commonDates 193x1 1544 double
payoff52 1x1 534464 struct
payoff52_01 1x1 534464 struct
payoff52_02 1x1 599872 struct
sp_HParam 1x1 15094 struct
sp_HParamSim 1x1 62402104 struct
sp_HParam_PriceMonthly - 17268 fints
sPrice_Monthly - 19192 fints
spGH_Sim 1x1 19628664 struct
spGHparam 1x1 52942 struct
spGHparam_FP 1x1 45106 struct
tyM - 51456 fints
tyMNS_NA_Param 1x1 232726 struct
tyMNS_NA_NA_Sim 1x1 38401280 struct </pre>Leihttps://ww2.mathworks.cn/matlabcentral/profile/authors/3061225-leitag:ww2.mathworks.cn,2005:Question/4070012018-06-22T20:30:42Z2018-06-22T23:39:49ZHow know the size of matrix after delete raws<p>What function do you use to know the size of the array after one or more rows are removed after a condition is achieved within a loop</p>asma khaledhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12364514-asma-khaledtag:ww2.mathworks.cn,2005:Question/4070132018-06-22T22:50:35Z2018-06-22T23:39:16ZHow to get value of radiobutton (or togglebutton) in GUI from another function?<p>I have a GUI file with only a togglebutton and a pushbutton. The following is the code of .m file of the GUI (without code of initialization):</p><pre> % --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton12</pre><pre class="language-matlab">% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
</pre><pre class="language-matlab">a=load('data.mat');
s=1;
g=[];
while s<=length(a)
g(s)=s*a(s);
if get(handles.radiobutton1,'Value')==0
break
end
s=s+1;
end
</pre><p>Basically, I want to get the value of the radiobutton and while it is not selected (value is 0) keep concatenating s*a(s) to array g. Then, when radiobutton is selected (its value is 1) stop the concatenation (finish), even if s is still <=length(a). However, when I press the push button I get the following error "reference to non-existent field handles.radiobutton1". How could I solve it?</p><p>PS: instead of radiobutton I could use togglebutton if required.</p><p>Thank you for your help.</p>Carlos HMhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13057615-carlos-hmtag:ww2.mathworks.cn,2005:Question/4070122018-06-22T22:21:20Z2018-06-22T23:37:20Z "index exceeds array bounds " error. Don't know whats wrong<p>Having trouble fixing this issue. Please help</p><pre class="language-matlab">for i = 1:1:4800
% Because in MATLAB/Octave indexing starts from 1
</pre><pre class="language-matlab">if image(i) < 255
image(i) = image(i) + 1;
end
</pre><pre> alphaLSH = uint32(bitshift(255, 24));
redLSH = uint32(bitshift(paletteR(image(i)), 16));
greenLSH = uint32(bitshift(paletteG(image(i)), 8));
blueLSH = uint32(bitshift(paletteB(image(i)), 0));</pre><pre> image(i) = typecast(bitor(bitor(alphaLSH, redLSH), bitor(greenLSH, blueLSH)), ...
'int32');
end</pre><p>Command window shows:</p><pre class="language-matlab">Index exceeds array bounds.
</pre><pre class="language-matlab">Error in matlab_example_create_image3 (line 116)
redLSH = uint32(bitshift(paletteR(image(i)), 16));
</pre>Paulina Maldonadohttps://ww2.mathworks.cn/matlabcentral/profile/authors/13009267-paulina-maldonadotag:ww2.mathworks.cn,2005:Question/4069872018-06-22T17:40:07Z2018-06-22T23:25:27Zfprintf leaving remainder of line <p>I am reading a txt file into matlab using fopen then textscan. the text is reading into a single cell that 43x1 (So if I wanted to get line 43 I would enter File{1}(43,1)). I change some of the lines and rewrite the file as such</p><pre> frewind(fileID)
for row=1:length(file{1})
fprintf(fileID,'%s\n',file{1}{row,1});
end</pre><p>When I reopen the text file it leaves a portion of line 43 in a new line 44</p><pre> (line 43) There is Ketchup on my hot dog
(line 44) on my hot dog</pre><p>The rest of the text file is written correctly, what is causing this to happen? even if there is a line 44 generated, if it was blank it would be fine</p>Keith Holmlundhttps://ww2.mathworks.cn/matlabcentral/profile/authors/2684788-keith-holmlundtag:ww2.mathworks.cn,2005:Question/4070162018-06-22T23:21:38Z2018-06-22T23:21:38ZHow to use Fourier Transform to convert time to frequency domain for real time data ?<p>Hello,
I have been doing my scientific project in Radar Sensor with Arduino.
I am reading the receiver value in voltage with respect to time.
I use Matlab Arduino tool to read the real time voltage values which is in time domain.
I need to convert those values in frequency domain.
How can i get the frequency domain with FFT function in Matlab ???
I have just a simple code to read voltage values from Radar.
Radar Info : 24 GHz.</p><p>%%% code %%%%%%%
clear a;
a = arduino('COM4','Nano');
x = 0;</p><p>while(1==1)
v =readVoltage(a, 'A0');
disp(v);
x =[x v];
plot(x);
drawnow;
grid;</p><p>Kindly shed some light in this area !!!!!</p>Esakki Ponraj Esakkimuthuhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12780953-esakki-ponraj-esakkimuthutag:ww2.mathworks.cn,2005:Question/4070152018-06-22T23:08:59Z2018-06-22T23:18:10ZUndefined function or variable 'CMMCore'<p>Hello, I am doing the Matlab Configuration <a href = "https://micro-manager.org/wiki/Matlab_Configuration">https://micro-manager.org/wiki/Matlab_Configuration</a>. I am confused by the vagueness of the first half of the instructions:</p><p><i>"The Micro-Manager Core Java API is contained in the file MMCoreJ.jar. Any Java program (including Matlab) that wants to use the Micro-Manager API needs to put MMCoreJ.jar in its ClassPath. When CMMCore Java object is first created in the calling program it will automatically attempt to load native library MMCoreJ_wrap. This library must be visible to the Java run-time. Default locations and exact names of libraries are platform dependent"</i></p><p>I followed steps 1-6 correctly. However, when I try to "CMMCore core = new CMMCore();" in the command prompt, I get the error "Undefined function or variable 'CMMCore'". I am doing this step from the Programming Guide <a href = "https://micro-manager.org/wiki/Micro-Manager_Programming_Guide">https://micro-manager.org/wiki/Micro-Manager_Programming_Guide</a>. This is the next step after following the matlab configuration guide linked above.</p><p>Thanks in advance!</p>Kiana Gohttps://ww2.mathworks.cn/matlabcentral/profile/authors/12989553-kiana-gotag:ww2.mathworks.cn,2005:Question/4070052018-06-22T21:08:11Z2018-06-22T23:12:41ZCustom Fit Fit options<p>I have created a custom fittype and tried let MATLAB itself find the starting point, given lower and upper bounds that I specify. However, those bounds seem to have been ignored when the fit process was performed (see attachments). Does anyone know how I can force MATLAB to search for the coefficients between the bounds I have specified? Thank you.</p>J.S.https://ww2.mathworks.cn/matlabcentral/profile/authors/12937214-j-stag:ww2.mathworks.cn,2005:Question/4070142018-06-22T22:59:52Z2018-06-22T23:05:03ZSplit a vector sequentially into parts provided specified length<p>For example, I have a vector</p><p>x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]</p><p>I have another vector n</p><p>n =[2, 2, 3, 3]</p><p>I wish to run a FOR loop to obtain,</p><p>x = [1, 2]
x = [3, 4]
x = [5, 6, 7]
x = [8, 9, 10]</p><p>Suppose n was:</p><p>n =[1, 2, 3, 4]</p><p>Then my FOR loop should return</p><p>x =[1]
x = [2, 3]
x = [4, 5, 6]
x = [7, 8, 9, 10]</p><p>How can this be done?</p>Bolinhttps://ww2.mathworks.cn/matlabcentral/profile/authors/2961758-bolintag:ww2.mathworks.cn,2005:Question/4070072018-06-22T21:45:48Z2018-06-22T23:02:58ZHow to make a piecewise linear plot from points?<p>My point coordinates are P1(1,1) ,P(3,2), P(3,3), P4(1,4). i need to make a piecewise linear plot i.e. line from P1 to P2, P2 to P3, P3 to P4? How can I do this simply? The number of points might increase.
I want the graph to be similar to the graph attached, the outer piecewise linear plot.</p>Basu Parmarhttps://ww2.mathworks.cn/matlabcentral/profile/authors/10868035-basu-parmartag:ww2.mathworks.cn,2005:Question/4065692018-06-20T14:55:17Z2018-06-22T22:52:04ZQuestion about regionprops3 'Orientation' angles / origin<p>I want to find out the spatial orientation of an object in a 3D image stack. For this, I am using regionprops3 of the Image Processing Toolbox. However the "order" of x-y-z angles confuses me, as the description sais "The angles are based on the right-hand rule. regionprops3 interprets the angles by looking at the origin along the x-, y-, and z-axis representing roll, pitch, and yaw respectively." Does this mean, the origin is at the lower front right corner of my image stack?</p><p>So my question is, can someone please help me translate the x-y-z angles into my image stack coordinate system, where the origin is at the top-left corner, y/rows goes down, x/columns to the right and z/pages "towards you"? As far as I figured, the "x" angle of regionprops seems to refer to what's my "Z"? Thanks a lot.</p>Isabel Ottmannhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12659887-isabel-ottmanntag:ww2.mathworks.cn,2005:Question/1352852014-06-18T04:00:00Z2018-06-22T22:31:13ZHow do I use SAVE with a PARFOR loop using Parallel Computing Toolbox?<p>I would like to save some variables to MAT files from inside a PARFOR loop. However I get an error:</p><pre class="error"> ??? Error using ==> parallel_function at 598
Error in ==> parallel_function>make_general_channel/channel_general at 894
Transparency violation error.
See Parallel Computing Toolbox documentation about Transparency.</pre>MathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:ww2.mathworks.cn,2005:Question/4066472018-06-20T19:37:14Z2018-06-22T22:12:18ZOpen fig file from an old version (2009) in 2015 version<p>I have some fig files I saved using Matlab 2009. Now I'm trying to open these files in Matlab 2015 but the figures are blanked. The Axis are correct, the labels are correct and also the colorbar are OK, but evething inside is blanked. How can I open these figures?</p><p><b>EDIT: Cassiano Bortolozo's "Answer" moved here:</b></p><p>Certainly Attached are the figures, the .png figure is how the .fig should be.</p>Cassiano Bortolozohttps://ww2.mathworks.cn/matlabcentral/profile/authors/8329212-cassiano-bortolozotag:ww2.mathworks.cn,2005:Question/4068832018-06-22T02:32:14Z2018-06-22T21:58:27ZSimulation time in Simulink<p>I need to run a simulation from x sec to y sec in Simulink enviroment. I go to Solver --> set Start time=x Stop Time=y and run simulation. But this doesn´t work because simulation keep starting @ 0 sec. Does anybody knows how to do it?</p>Pablo Pahttps://ww2.mathworks.cn/matlabcentral/profile/authors/10018017-pablo-patag:ww2.mathworks.cn,2005:Question/4070102018-06-22T21:53:29Z2018-06-22T21:53:29Zproblems about feature localization and how to snap a grid<p>I am writing a GUI program. The program can recognize some features in the face. Firstly, I initialized some original features in the face. And the next stage is that I need to adjust the position of the points by manual. Therefore, the first problem is that I need to snap the specific point automatically. At the meanwhile, I refresh the image and show the position of new features in each drawing. I have researched for a week now. but I cannot find the answers. so I need your comments.thank you.
like the image attached, I want to adjust the point manually. surely, I require the mouse to snap the marker automatically.</p>min haohttps://ww2.mathworks.cn/matlabcentral/profile/authors/8288333-min-haotag:ww2.mathworks.cn,2005:Question/4070092018-06-22T21:52:43Z2018-06-22T21:52:43ZS-Function read from texfile<p>Hi all,</p><p>i want to read out values from a textfile with an S-Function.
The size of the textfile is not known. The S-Function should therefore have a dynamically output port. Can someone provide me an S-Function, which can fullfill it? I would be very happy about that.</p><p>Thanks!</p><p>Textfile can be like:</p><p>0 2 3 4 5 7 8 9 10
11
12...</p>octus_mahttps://ww2.mathworks.cn/matlabcentral/profile/authors/8144733-octus_ma