https://nl.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-12-12T16:00:40Ztag:nl.mathworks.com,2005:Question/3724962017-12-12T08:14:42Z2017-12-12T16:00:40Z 2016b exe size is too large<p>Hello All,
I was currently using 2012b Matlab and built executables for the same. While I shifted to 2016b Matlab (due to the requirement of tools to run in Windows 10)
I find that the executable sizes are quite large.
2012 — 540kB
2016 — 1.05MB</p>Akshata Mhttps://nl.mathworks.com/matlabcentral/profile/authors/7624087-akshata-mtag:nl.mathworks.com,2005:Question/3725832017-12-12T15:55:54Z2017-12-12T15:55:54Zhow to generate random matrix with known matrix<p>Hello Everyone,
For example I have;
a=[1 2 3];
b=[4 5];
s=8;</p><p>I can create matrix(es?) like this;
matrix1=[a b s]; (ans=[1 2 3 4 5 8])
matrix2=[a s b]; (ans=[1 2 3 8 4 5])
matrix3=[s b a]; (ans=[8 4 5 1 2 3]) etc...</p><p>But how can I make Matlab generate all the possible (3!) combinations without writing them manually myself?
Is it even possible?
I am aware that it is not that hard to do with 6 different outcomes but I have (15!) combinations that I have to generate.
I appriciate all answers.
Thank you.</p>Melike Öztürkhttps://nl.mathworks.com/matlabcentral/profile/authors/9821476-melike-ozturktag:nl.mathworks.com,2005:Question/3713902017-12-06T10:11:13Z2017-12-12T15:55:17ZHow to initiate state after a filter<p>Hello,</p><p>I am using simulink with 2 input signals (from a measurements, meaning with a sampled time) that i am filtering (using transfer function). The output of there 2 filters are summed and then used as a denominator for a division.
Logically, when i run the simulation, the first block (also a filter) at the output of the division rises an issue "At time 0.0 is not finite. The simulation will be stopped. There may be a singularity in the solution. If not, try reducing step size".
I think it's mean that the first division operation at t=0 can't obviously work because of the 0 division. How can i fix the value of the first sample to avoid this issue?</p><p>Thank you,</p>FattyBumBumhttps://nl.mathworks.com/matlabcentral/profile/authors/11689544-fattybumbumtag:nl.mathworks.com,2005:Question/3725582017-12-12T13:31:44Z2017-12-12T15:54:58ZHow to call the rows of a matrix without the for loop<p>Hi I have a matrix A=[1 2 3 4 5;6 7 8 9 10; 11 12 13 14 15] and I want to call each row of the matrix one by one as an input to my program. i.e, A(1,:) is taken as first input, A(2,:) is the second input and finally A(3,:), just like it is done in a loop, but is there any way that I can do the same without using a for loop.</p><p>Any help would be much appreciated.</p>Waheeb Butthttps://nl.mathworks.com/matlabcentral/profile/authors/9693863-waheeb-butttag:nl.mathworks.com,2005:Question/2860472016-05-27T08:00:58Z2017-12-12T15:53:19ZCan i call Raspberry matlab commands in simulink<p>Hello,</p><p>With the support package for Raspberry Pi come in handy methods to acquire data from the Pi device. So i want to use the putFile, getFile and system methods, that can be used in matlab code in simulink, too. But when i try to instantiate a pi instance in a matlab function in simulink, i get a parsing error.</p><p>--------------------------------</p><p>The 'matlab.mixin.CustomDisplay' class does not support code generation.</p><p>Function 'raspi.m' (#76.3324.7682), line 110, column 9:
"function obj = raspi(hostname, username, password, port)"</p><p>Launch diagnostic report.</p><p>--------------------------------------</p><p>I dont see another way than to implement matlab code in simulink, but it wont work.
How can i use these methods in simulink?</p><p>thanks in advance:)</p>Abdulkadir Erogluhttps://nl.mathworks.com/matlabcentral/profile/authors/7061544-abdulkadir-eroglutag:nl.mathworks.com,2005:Question/3546142017-08-30T16:29:29Z2017-12-12T15:53:17ZCD to OneDrive doesn't work on Windows 10 build 16273.1<p>I recently upgraded to the newest version of the Windows available to insiders and now I can't CD to OneDrive in Matlab. I can still use "dir" to list the contents of the OneDrive folder, and I can even view the files in it that I had open previously, but I can't actually change the working directory to reach them. Symbolic linking and shortcuts also don't work. I can still cd to OneDrive from both Windows command line and the WSL terminal, so it seems to be a Matlab specific problem.</p>James Bellhttps://nl.mathworks.com/matlabcentral/profile/authors/5422962-james-belltag:nl.mathworks.com,2005:Question/3725652017-12-12T14:21:55Z2017-12-12T15:52:26Zproof if value is greatest of a range of Values<p>Dear all,</p><p>i have got following problem. I am very thankful for any answer!
See m+/-50: I want to refer to a range of rows and see if for example cell(230,1) has got the greatest value of all 50 cells above and below it (180:280,1). I tried with: (m-50:m+50,1) but it doesn´t work. Can u help me?</p><pre class="language-matlab">if true
for m=1:e-a
if X(m,3)==1 && X(m,1)>=X(m+/-50,1)
X(m,5)=1;
else
disp('zero')
end
end
</pre>Jonas Maurerhttps://nl.mathworks.com/matlabcentral/profile/authors/10725735-jonas-maurertag:nl.mathworks.com,2005:Question/3723992017-12-11T20:29:29Z2017-12-12T15:51:22ZI need to solve or just plot a function p(x,y) of two variables knowing just its gradient which is a vector, any suggestions <p>I need to solve or just plot a function p(x,y) of two variables knowing just its gradient which is a vector, any suggestions</p>stayli nawfalhttps://nl.mathworks.com/matlabcentral/profile/authors/5215286-stayli-nawfaltag:nl.mathworks.com,2005:Question/3704272017-12-01T12:51:48Z2017-12-12T15:51:19ZHow can I solve an integral equation with an unknown kernel?<p>The equation I am trying to solve is:</p><img src = "/matlabcentral/answers/uploaded_files/96903/CodeCogsEqn.gif"><p>where f(x) and h(x) are both complex and known, and g(x) is an unknown function. Presumably, the result should be a function g(x), however, it is not to be excluded that g(x) could actually be an operator instead. Can this be solved for either cases in MATLAB?</p><p>Thanks!</p>Sergio Manzettihttps://nl.mathworks.com/matlabcentral/profile/authors/10573158-sergio-manzettitag:nl.mathworks.com,2005:Question/3725822017-12-12T15:50:28Z2017-12-12T15:50:28ZHow to merge two images of different sizes ??<p>How to merge two images of different sizes so that the resultant merged image contains bigger image contains smaller image at a specific location in bigger image ??</p>Amit Vermahttps://nl.mathworks.com/matlabcentral/profile/authors/11735938-amit-vermatag:nl.mathworks.com,2005:Question/2174442015-05-18T20:55:53Z2017-12-12T15:50:20ZMatlab jokes or puns<p>Are there any good Matlab jokes? I don't mean <tt>why</tt> or any other Easter eggs, I mean good jokes involving Matlab. Actually, that <tt>bar</tt> may be a bit too high. Any jokes, good or bad, let's hear 'em.</p>Chad Greenehttps://nl.mathworks.com/matlabcentral/profile/authors/1062128-chad-greenetag:nl.mathworks.com,2005:Question/3725712017-12-12T14:46:33Z2017-12-12T15:49:57ZHow to find position of a time vector in another time vector?<p>Hi</p><p>I have two time vectors, one has random time spacing like A=[' 01/01/2001', '05/01/2001, ....], the other time vector has daily time like B=[' 01/01/2001', '01/02/2001', ....]. I like to find a position of each element of A in vector B. What is the fastest way? I don't want to write a loop for find each element. is there a faster way to output a position vector directly? Thanks a lot. I appreciate your help.</p>Yongnuan Liuhttps://nl.mathworks.com/matlabcentral/profile/authors/11447515-yongnuan-liutag:nl.mathworks.com,2005:Question/3725722017-12-12T14:58:24Z2017-12-12T15:47:51ZHow to implement a Correlated Brownian Motion correctly<p>I have trouble implementing a Correlated Brownian Motion.
I need the simulation for 1000 paths and T=5.
Only the values of the evolution for t=1 and T=5 are relevant.
The following code is running, but does not return the expected values.
Does anybody know what I did wrong?
Thankful for any advice or hint!</p><pre class="language-matlab">X1=100;
X2=90;
r=0.03;
sigma1=0.25;
sigma2=0.25;
rho=0.5;
T=5;
</pre><pre class="language-matlab">sigma=[sigma1 0;0 sigma2];
corr=[1 rho;rho 1];
cov=sigma*corr*sigma;
</pre><pre class="language-matlab">R=chol(cov,'lower');
</pre><pre class="language-matlab">N=1000;
</pre><pre class="language-matlab">X1_t=zeros(N,T+1);
X1_t(:,1)=A_0;
X2_t=zeros(N,T+1);
X2_t(:,1)=L_0;
</pre><pre class="language-matlab">dt=1;
</pre><pre class="language-matlab">for i=1:N
X=randn(T,2);
W=X*R;
for j=2:T+1
X1_t(i,j)=X1_t(i,j-1)*exp(r*dt+sigma1.*W(j-1,1)-(sigma1.^2./2)*dt);
X2_t(i,j)=X2_t(i,j-1)*exp(r*dt+sigma2.*W(j-1,2)-(sigma2.^2./2)*dt);
end
end
</pre>Ninahttps://nl.mathworks.com/matlabcentral/profile/authors/8072181-ninatag:nl.mathworks.com,2005:Question/3725812017-12-12T15:47:30Z2017-12-12T15:47:30Zcould anyone help me to execute the following code as i am unable to get the result.<p>UE=[2 4 6 8 10];
SC=[20 40 50 60 80];
for t=1:length(UE)
for r=1:length(SC)
G=rand(UE(t),SC(r));
B=zeros(UE(t),SC(r));
N=2;
for g=1:SC(r)
C= B(:,g);
zeroidx = find(~C);
replaceidx = zeroidx(randperm(numel(zeroidx), N-sum(C)));
C(replaceidx) = 1 ;
S(:,g) = [C];
end
Z = G .* S
end
end</p>Prabha Kumaresanhttps://nl.mathworks.com/matlabcentral/profile/authors/3496859-prabha-kumaresantag:nl.mathworks.com,2005:Question/3725142017-12-12T09:42:53Z2017-12-12T15:47:18ZHow can I freeze a subplot in a while loop?<p>How can I plot several graphs using subplot in a while loop.
The following coding erases the nth graph and plots the (n+1)th graph.</p><p>y=1;
z=1;
while z==1
.
.
.
.
.
figure
subplot(y,1,y)
plot(years,run_rate,'b-s')
hold on</p><p>z= input('Would you like to analyze another player/team?\n Press:\n 1. Yes\n 2.No');
y=y+1;
end</p>Aamna Samihttps://nl.mathworks.com/matlabcentral/profile/authors/11355947-aamna-samitag:nl.mathworks.com,2005:Question/1668712014-12-16T05:00:00Z2017-12-12T15:45:54ZHow will running the restoredefaultpath and savepath commands affect my custom paths and how do I back up my custom paths?<p>I setup custom paths from within MATLAB but now need to restore the default path. How does the restoredefaultpath command affect my custom paths and how can I back them up before running it?</p>MathWorks Support Teamhttps://nl.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:nl.mathworks.com,2005:Question/3725802017-12-12T15:45:32Z2017-12-12T15:45:32Zcan anyone help me with the code for min cost for a flat fin heat exchanger?<p>where l,t,h,spacing,w,and number are the variables. The objective function is to minimise the cost.</p>Divin Varghesehttps://nl.mathworks.com/matlabcentral/profile/authors/11064231-divin-varghesetag:nl.mathworks.com,2005:Question/3725792017-12-12T15:43:32Z2017-12-12T15:48:55Zhow to plot dots along a straight<p>Hello, I've got a problem on Matlab.</p><p>I want to plot several points (the points are along a line).
There is multiples lines, they are all parallel, and perpendicular to an other line.</p><p>Thank you for your help !!</p><img src = "/matlabcentral/answers/uploaded_files/98335/Capture%20d%E2%80%99%C3%A9cran%202017-12-12%20%C3%A0%2016.44.20.png">samuel le goffhttps://nl.mathworks.com/matlabcentral/profile/authors/11735915-samuel-le-gofftag:nl.mathworks.com,2005:Question/3725782017-12-12T15:41:15Z2017-12-12T15:41:15ZMatlab System: Variable-Size Discrete-State<p>I'm currently working with <b>Matlab Systems</b> and want to implement them in Simulink. Therefore, a simple system shall be developed, which uses mechanical system parameter <i>(M,K,D)</i> and <i>dt</i> to estimate structural responses <i>(x,v,a)</i>.</p><p>This approach works perfectly for SISO systems, <i>M,K,D</i>: 1x1. Unfortunately, MIMO systems (e.g. <i>M,K,D</i>: 2x2) lead to false estimates: the state vector has the wrong dimension (4x2 for 2-dof).</p><p>Furthermore, I'm not able to set <b>variable-size discrete-states</b>?! (s. getDiscreteStateSpecificationImpl -> sz must be fixed-size?).</p><p>Is there anybody, who can help with matlab system objects? The developed code is given in the attachments.</p>Armin Lenzenhttps://nl.mathworks.com/matlabcentral/profile/authors/27603-armin-lenzentag:nl.mathworks.com,2005:Question/3725442017-12-12T12:03:42Z2017-12-12T15:41:00ZStacked multi-cuboid geometries with PDE Toolbox for thermal analysis <p>With the PDE Toolbox, I know that I can use the multicuboid function to create a stack of cuboids for thermal analysis, each with their own thermal characteristics. However, it appears that each of the resulting cuboids must have the same width and height as all other cuboids in the stack. To more accurately represent a power semiconductor that I am analyzing, each cuboid would ideally have a different size (thickness, width, and depth). Is it possible to create such a geometry?</p>David Naviauxhttps://nl.mathworks.com/matlabcentral/profile/authors/11654400-david-naviauxtag:nl.mathworks.com,2005:Question/3725772017-12-12T15:40:25Z2017-12-12T15:40:25Zwhat is the difference between hold and plot of two curves in the same figure ?<pre> i want to plot cos(x) and sin(x) in the same figure, i have two ways :
i can write for example :
X=0:pi,
Y=cos(X);
Z=sin(X);
Plot(X,Y,X,Z)
or the second way :
X=0:pi;
Y=cos(X);
Z=sin(Z);
Plot(X,Y)
Hold on
Plot(X,Z)
what is the difference between these two ways ?</pre>diadalinahttps://nl.mathworks.com/matlabcentral/profile/authors/6918672-diadalinatag:nl.mathworks.com,2005:Question/3725452017-12-12T12:07:47Z2017-12-12T15:40:08Zhow to combain matrix with vector<p>if I have matrix a = [9 8 7; 6 5 4]
and vector v = [1 2 3 4 5]
I want to combaine matrix like this</p><pre class="language-matlab">[9 8 7 inf inf; ...
6 5 4 inf inf; ...
1 2 3 4 5]
</pre><p>thank you!!</p>nadav regevhttps://nl.mathworks.com/matlabcentral/profile/authors/11377497-nadav-regevtag:nl.mathworks.com,2005:Question/3719262017-12-08T16:29:26Z2017-12-12T15:39:45ZConverting 3D patches to 3D image<p>Hey guys,</p><p>I have a bunch of patches generated from a 3D image of size 64x64x25. I now want to retore the image with these pixels. I was able to do this with the following code:</p><pre class="language-matlab">function [img] = patch2im_2d_time(patch, size_img, size_patch, size_skip, border)
Nx = size_img(1);
Ny = size_img(2);
Nt = size_img(5);
</pre><pre class="language-matlab">psz1 = size_patch(1);
psz2 = size_patch(2);
psz3 = size_patch(3);
</pre><pre class="language-matlab">%Extract blocks. This is not necessary
patches = reshape(patch, [psz1 psz2 psz3 size(patch,2)]);
c = 1;
img2 = zeros(squeeze(size_img));
%Count for each pixel how many times we added smth to it.
add_count = zeros(size_img);
</pre><pre class="language-matlab">%The first three loops, loop through all the pixels in the image
for d=1:Nt-psz3+1
for j=1:Nx-psz2+1
for i=1:Ny-psz1+1
%Here we get the next patch. The next patch is always
%the patch that has the pixel at i,j,d at its top front corner.
current_patch = patches(:,:,:,c);
%counter for the next patch
c = c + 1;
%In this loop we add the patch values of each pixel in the
%patch to the image. i,j,d is the base. We add the offset
%ii jj and dd to it. This iteration takes psz^3 many
%iterations.
for dd=1:psz3
for ii=1:psz2
for jj=1:psz1
img2(i+ii-1,j+jj-1,d+dd-1) = img2(i+ii-1,j+jj-1,d+dd-1) + current_patch(ii,jj,dd);
add_count(i+ii-1,j+jj-1,d+dd-1) = add_count(i+ii-1,j+jj-1,d+dd-1) + 1;
end
end
end
</pre><pre> end
end
end
img = flipud(rot90(img2 ./ add_count,1));
end</pre><p>The problem is that it runs for 15 (!) seconds on my machine. I have an implementation that does it for the 2D case in under 1 second. I know, the for loops are just horrible, but I can't figure out a better way.
If you quickly want to try some things, I suggest that you use</p><pre class="language-matlab">reshape(linspace(1,1000,1000),[10 10 10]);
</pre><p>To generate a 10x10x10 matrix that has the indices as entries. That is how I came up with the bad solution.
It would be great if somebody could provide an alternative, as I am using this in an iterative algorithm and the overhead is horrible (even for testing).</p>Julian Büchelhttps://nl.mathworks.com/matlabcentral/profile/authors/8867806-julian-bucheltag:nl.mathworks.com,2005:Question/3720532017-12-09T16:42:23Z2017-12-12T15:39:11ZI have two computers, one with a 32 bit windows 7 and another with 64 bit windows 10. I have a student license. Can I install and activate MATLAB in both of my computers with my license?<p>I got a student license and I want to install MATLAB in two computers, one with a 32 bit windows (windows 7) and another with 64 bit windows (windows 10). I have installed the software in my computer with 32 bit windows. Now I want to install it in my other computer. That's the reason of my question.</p><p>Thank you</p>oscar arizahttps://nl.mathworks.com/matlabcentral/profile/authors/11705186-oscar-arizatag:nl.mathworks.com,2005:Question/3725762017-12-12T15:35:21Z2017-12-12T15:37:05Zhow can i generate these two chromosomes?<p>Hi Everyone
I'm working on a flexible job shop problem with preventive maintenance (PM)tasks . We have a set of jobs and machines .respectively Jobs=[2 5 7; 1 3 7; 5 4 7;9 2 1;2 4 1;7 5 3;1 4 7;3 5 7;4 2 7], Machines=[M1,M2,M3]. And also there is a time window(range) for PM tasks of machines which must be done in it and every PM task has a duration PM=[0 13 3;2 9 1;0 8 3](the first column is the earliest time that PM task can begin the second column is the time that task must be end and last column is the PM task duration. Now I want 2 parallel chromosomes that the first one be the number of machines which is chosen by random and the second one is the job that randomly was selected from each row of the jobs matrix .Finally there must be two matrix like these:
Machines chromosome:3 1 2 2 1 3 3 1 2 1 3 2 (number of machines)
Jobs and PM chromosome: 1 2 3 3 1 2 2 3 1 3 1 2(9 numbers are for the positions of jobs matrix and others are for pm tasks)</p><p>any help would be appreciated.</p>Arash Aphttps://nl.mathworks.com/matlabcentral/profile/authors/11714892-arash-aptag:nl.mathworks.com,2005:Question/3725752017-12-12T15:33:48Z2017-12-12T15:33:48Z5枚の画像データを読み込み、それぞれのデータを記憶していきたいのですが………<p>5枚の画像をそれぞれ読み込んでデータを記憶させたいのですが、なぜか5枚目のデータしか表示されません。どうしたらよいのか教えていただけませんか？</p>Takuya Nagaihttps://nl.mathworks.com/matlabcentral/profile/authors/10752938-takuya-nagaitag:nl.mathworks.com,2005:Question/3725682017-12-12T14:33:55Z2017-12-12T15:31:21ZHow Are Calculations Done for Variable That's Inclusive of Itself?<p>Consider the following simple scenario:</p><pre class="language-matlab">x=x+1
</pre><p>In terms of computational efficiency and speed, I'm curious how this calculation is handled. x is inclusive of itself and overwriting itself with a new value. So I assume x has to first be moved to RAM to then complete the calculation and subsequently store the new value. I have a very large script, with large matrices, many loops, and lots of similar calculations. The script takes a long time to run and I'm wondering if this is a bottleneck that slows down the script. An alternative might be as follows, but I'm not sure if I'd gain anything.</p><pre class="language-matlab">temp=x
x=temp+1
</pre><p>In this latter case, x is not inclusive of itself in the calculation, so I wonder if this is more efficient.</p><p>I'd appreciate any input.</p><p>Thanks,</p><p>M Ridzon</p>Matthewhttps://nl.mathworks.com/matlabcentral/profile/authors/1259708-matthewtag:nl.mathworks.com,2005:Question/3725742017-12-12T15:31:21Z2017-12-12T15:31:21ZProblems to run .mat file in eeglab<p>Hi everyone,</p><p>When I try to open my .mat files (gathered in Acqknowledge 5.0) in eeglab (File -> Import data -> Using eeglab functions and plugins -> From ASCII/float file or Matlab array), I get this error (screenshot)</p><p>Does anyone have a solution for this?</p>Marlies Vercruyssehttps://nl.mathworks.com/matlabcentral/profile/authors/11734502-marlies-vercruyssetag:nl.mathworks.com,2005:Question/3712802017-12-05T19:42:19Z2017-12-12T15:30:44ZI am not getting multiple graphs(iterative) when I run the code for a coupled bvp ODE using bvp4c<p>Two ODEs are:</p><p>F"=G(G^2+gamma^2)/(G^2+lambda*gamma^2)</p><p>G'= 1/3F'^2-2/3(F*F")</p><p>subject to:
F(xi)=alpha/2, F'(xi)=1 at xi=0 where 'alpha' is a parameter (wall parameter)</p><p>F'(xi)= 0 as <i>xi</i> tends to infinity</p><p>I should be getting a multiple graphs varying the parameter ' <i>alpha</i>'</p><p>The code that I have run is:</p><pre class="language-matlab">function sol= proj
clc;clf;clear;
global lambda gama alp
lambda=0.5;
gama=1;
pp=[0:0.5:1.0];
figure(1)
plot(2,1);
solinit= bvpinit([0:0.01:10],[0,1,0]);
for alp= pp
sol= bvp4c(@projfun,@projbc,solinit);
solinit= sol;
plot(2,1);plot(sol.x,sol.y(2,:))
end
end
function f= projfun(x,y)
global lambda gama
f= [y(2);y(3)*(y(3)^2+gama.^2)/(y(3)^2+lambda*gama.^2);y(2)^2/3-(2*y(1)*y(3)*(y(3)^2+gama.^2))/(3*(y(3)^2+lambda*gama.^2))];
end
function res= projbc(ya,yb)
global alp
res= [ya(1)-alp/2; ya(2)-1.0; yb(2)];
end
</pre>naygarphttps://nl.mathworks.com/matlabcentral/profile/authors/11284588-naygarptag:nl.mathworks.com,2005:Question/3725732017-12-12T15:27:15Z2017-12-12T15:27:15ZRunning MATLAB in headless mode.<p>Is there a way to run MATLAB in headless mode when you don't have the Parallel Computing Toolbox (PCT)? I have used the PCT in the past and it's really nice when I have had to create and save a large number of plots that they can be batched and run in a headless mode. Is there a way to run MATLAB in headless mode without the PCT?</p>Keithhttps://nl.mathworks.com/matlabcentral/profile/authors/3157258-keithtag:nl.mathworks.com,2005:Question/3723792017-12-11T19:43:35Z2017-12-12T15:22:48ZCan one run a matlab script from the command line and pass arguments to it **without making it into a function**?<p>I was to run a MATLAB script from the terminal and pass arguments to it. I know I can make it into a function to pass arguments to it but I don't want to make it into a function. Is there a different way? Like can one get the environment variables from the terminal or something as an alternative? As in:</p><pre class="language-matlab">SLURM_ARRAY_TASK_ID = int(os.environ['SLURM_ARRAY_TASK_ID'])
SLURM_JOBID = int(os.environ['SLURM_JOBID'])
</pre><p>as it would be done in python?</p>Brando Mirandahttps://nl.mathworks.com/matlabcentral/profile/authors/2706824-brando-mirandatag:nl.mathworks.com,2005:Question/3725702017-12-12T14:42:44Z2017-12-12T15:16:08ZInsert comma/point in a number <p>I have a temperature data in a char format without comma or point to divide the decimal and I want to insert a point after the second number (staring from the left):</p><pre class="language-matlab">char= 225800 and I want t=22.58
</pre><p>Can someone help me, please?</p><p>Thank you</p><p>Michela</p>Michela Longhihttps://nl.mathworks.com/matlabcentral/profile/authors/8079437-michela-longhitag:nl.mathworks.com,2005:Question/3725272017-12-12T10:30:30Z2017-12-12T15:13:09ZI am getting error in edge function like "Attempt to execute SCRIPT edge as a function:" b=edge(img,'canny',0.40); Can someone solve this error?<p>a=imread('D:\canal images\df.jpg');
imshow(a);
title('Original');</p><p>img=rgb2gray(a);
imshow(img);
title('Grayscale');</p><p><b>b=edge(img,'canny',0.40);</b>
figure,imshow(b);
title('canny');</p>Jainee Solankihttps://nl.mathworks.com/matlabcentral/profile/authors/10813897-jainee-solankitag:nl.mathworks.com,2005:Question/3725302017-12-12T10:52:13Z2017-12-12T15:09:15ZHow can I reduce the number of digits?<p>Hi,</p><p>while i'm running Matlab, I have to run some simulations and their results are written in a variable workspace in Matlab. However, the precision (number of digits after the decimal) is too high and I want to reduce it to 4. I tried many codes but none worked.</p><p>Any help is appreciated!</p><p>P.S. my problem is not the display format but when I rewrite or copy the results. Have a look!</p><img src = "/matlabcentral/answers/uploaded_files/98303/problem.JPG">Abdulrahman Dahashhttps://nl.mathworks.com/matlabcentral/profile/authors/11442106-abdulrahman-dahashtag:nl.mathworks.com,2005:Question/2313092015-07-27T11:15:35Z2017-12-12T15:07:33ZBest graphics card for GPU computing<p>Dear all,
I'm beginning a new project where I will need to use GPU for my research.
Could you help me to chosse the best one in the market at this stage (no real limit for its cost).
Best regards.
Sébastien</p>Sébastien MAILFERThttps://nl.mathworks.com/matlabcentral/profile/authors/2658786-sebastien-mailferttag:nl.mathworks.com,2005:Question/3725512017-12-12T12:35:04Z2017-12-12T15:06:46ZWhat can I write in a MATLAB function block in Simulink?<p>Hi
I am working with Simulink. I wrote a function in Matlab that basically does a circular shift, and I wanted to put it into Simulink by using the MATLAB function block. The thing is that if I write</p><pre class="language-matlab">function y= shift_with0(u,s)
y = circshift(u,s);
y(1:s)=0;
end
</pre><p>no problem and everything is working. But, I wanted to allow as inputs also vectors, so I wrote this function</p><pre class="language-matlab">function y= shift_with0(u,s)
if isvector(s)
pm=sign(s);
inegatif = sum(pm(:)==-1);
s = inegatif;
end
y = circshift(u,s);
y(1:s)=0;
end
</pre><p>In Matlab is working, but the Simulink block not. So, I assume that is the "if" part that Simulink does not accept. In general, could someone clarify for me what I can write/not write in a MATLAB function block?
Thanks</p>Mariahttps://nl.mathworks.com/matlabcentral/profile/authors/5027828-mariatag:nl.mathworks.com,2005:Question/3723382017-12-11T16:51:04Z2017-12-12T15:04:15ZHow to plot the difference between y components for all x?<p>I have plotted the energy consumption of two model house on one plot using roughly the following code (I do not have the exact code in-front of me):</p><pre class="language-matlab">t = 0:24; %hour of day
iEc = [measured values for model A]; %length =25
Ec = [measured values for model B;] %length = 25
</pre><pre class="language-matlab">figure
plot(t, iEc, '-or', t, Ec, '-ob'); %after this, there are graph labels
</pre><p>I am satisfied with how everything turned out but just as an extra feature, I'd like to add a line between the y component of the two curves at the same t value on the same graph. For example, at t = 1 , i'd like to plot a line from (y of iEc) to (y of Ec) and list the difference next to it. This is similar to what I'd like to do but I'd like to add the difference between the curves: i.stack.imgur.com/G2Azd.png</p><p>I'm not 100% on how to do this, but I was thinking a for loop may be the best way to do this for all t. Any help or suggestions are appreciated. Thank you.</p>SKhttps://nl.mathworks.com/matlabcentral/profile/authors/8850582-sktag:nl.mathworks.com,2005:Question/3724422017-12-11T23:05:59Z2017-12-12T15:02:39ZWorking with dde23 for a simple problem<p>I'm trying to solve this: xdot = -Lx(t-1) where x is a 3x1 vector and L a constant 3x3 matrix. The initial conditions for x are [0 0 0]'for t<0. For some reasons, I'm having trouble with framing the DDE.I have seen the comprehensive manual already. Yours inputs are appreciated. Thanks.</p>Deepayan Bhadrahttps://nl.mathworks.com/matlabcentral/profile/authors/8596145-deepayan-bhadratag:nl.mathworks.com,2005:Question/446672012-07-27T07:25:27Z2017-12-12T14:58:43ZKeithley 6514 electrometer control via RS-232<p>Hi,</p><p>I am trying to communicate with Keithley 6514 via RS-232. When I run my m-code Keithley responds, so it means there's a communication.</p><p>However voltage values, I am getting are incorrect.</p><p>I am using modified code, which I have found on internet:</p><pre> s = serial('COM1');
set(s,'BaudRate',9600,'Terminator','CR','Timeout',1, 'DataBits', 8, 'Parity', 'none');
fopen(s);
fprintf(s,'*rst'); %reset instrument
fprintf(s,'*idn?'); %identify the system connected
out = fscanf(s);
if strfind(out,'KEITHLEY') %&& strfind(out,'6514') %M6514
fprintf(s,'*rst'); %reset instrument
fprintf(s,'volt:dc:rang 200'); %set voltage range
fprintf(s,'func "volt:dc";:read?'); %read voltage range
out = fscanf(s);
disp(out);
fprintf(s,':syst:loc'); %set instrument to local use
get(s);
fclose(s); %close and disconnect from com port
fclose(s);
delete(s);
clear s;
out = eval(out);
out = out*10;
out = round(out);
out = out/10;
disp(out);
else
fprintf(s,'*rst'); %reset instrument
fprintf(s,':syst:loc')
fclose(s); %close and disconnect from com port
fclose(s);
delete(s);
clear s;
msgbox('Check connections DMM!','MCS','warn');
end;</pre><p>In the end I am getting three values, instead of one voltage value. I am getting -6.325239E-04,+2.887642E+03,+5.120000E+02, while real value is 8.236V.</p><p>I don't know where is the problem and how to solve it, but I get:</p><pre> Error using keithley_read_1 (line 19)
Error: Unexpected MATLAB operator.</pre><p>This is regarding line: out = eval(out);</p><p>Can someone help me with this?</p><p>Regards,
Bart</p>Barthttps://nl.mathworks.com/matlabcentral/profile/authors/3585621-barttag:nl.mathworks.com,2005:Question/3723882017-12-11T20:05:25Z2017-12-12T14:57:43ZWhy doesn't getenv work on MAC OS X?<p>I was trying to get environment variables that I know exist but it returns empty arrays...is that normal?</p><pre class="language-matlab">hello =
</pre><pre> 0�0 empty char array</pre><pre class="language-matlab">res =
</pre><pre> 0�0 empty char array</pre><pre class="language-matlab">>>
</pre><p>from running</p><pre> hello = getenv('hello')
res = getenv('SYSTEMROOT')</pre><p>----</p><p>These are the scripts I am exactly running:</p><pre class="language-matlab">#!/bin/bash
alias matlab='/Applications/MATLAB_R2017a.app/bin/matlab -nodesktop -nosplash'
</pre><pre class="language-matlab">hello=hellohello
echo $hello
matlab -nodesktop -nosplash -nojvm -r "test_sh"
</pre><p>which runs the following:</p><pre class="language-matlab">clear;
%SLURM_JOBID = getenv('SLURM_JOBID')
%SLURM_ARRAY_TASK_ID = getenv('SLURM_ARRAY_TASK_ID')
hello = getenv('hello')
res = getenv('SYSTEMROOT')
PATH = getenv('PATH')
</pre>Brando Mirandahttps://nl.mathworks.com/matlabcentral/profile/authors/2706824-brando-mirandatag:nl.mathworks.com,2005:Question/3725352017-12-12T11:23:28Z2017-12-12T14:54:22ZWhy it gives error to matlab's own function<p>Undefined function 'getAxesTransformationMatrix' for input arguments of type 'matlab.graphics.axis.Axes'.
Error in View (line 84)
varargout{1} = getAxesTransformationMatrix(hAxes);</p><p>It gives me that error when I call View.m which is a predefined function in Matlab R2015a</p>Stelios Fanourakishttps://nl.mathworks.com/matlabcentral/profile/authors/10865530-stelios-fanourakistag:nl.mathworks.com,2005:Question/3658302017-11-08T12:15:18Z2017-12-12T14:53:21Zmex -setup can't find compiler for MATLAB 2017b on macOS High Sierra 10.13.1 and Xcode 9.1<p>I'm trying to add C and C++ compiler for MATLAB 2017b on my mac but it gives error</p><pre class="language-matlab">/bin/bash: sh: command not found
</pre><p>and</p><pre class="language-matlab">Warning: Xcode appears to be installed, but it has not been configured. Run "osascript -e 'do shell script "xcode-select -switch /Applications/Xcode.app" with administrator privileges'" to configure Xcode. You must be an administrator of this computer to complete this action.
</pre><p>So, when I run osacript... it gives error</p><pre class="language-matlab">/bin/bash: osascript: command not found
ans =
127
</pre><p>I already did</p><pre class="language-matlab">sudo xcode-select -switch /Applications/Xcode.app/
</pre><p>and changed</p><pre class="language-matlab">MACOSX_DEPLOYMENT_TARGET="10.13"
</pre><p>which was 10.9 in clang_maci64.xml and clang++_maci64.xml files. Can anybody help me to solve this issue.
Thank you.</p>Deepak Ingolehttps://nl.mathworks.com/matlabcentral/profile/authors/2422222-deepak-ingoletag:nl.mathworks.com,2005:Question/3721372017-12-10T09:20:28Z2017-12-12T14:52:44ZHow to plot categorical line over bar plot?<p>I want to plot a line over each grouped bar plot, like on the figure below. In the code below it is RSMEref of the same size as the RSME bar plot. I have been trying for the while but nothing works. How can I do that?</p><img src = "/matlabcentral/answers/uploaded_files/98021/untitled.png"><pre> RSME = [0.0191 0.0291 0.0362 0.0648 0.0884;
0.0176 0.0552 0.0802 0.0961 0.0810;
0.0139 0.1130 0.1737 0.2191 0.1905;
0.0155 0.1792 0.2656 0.2553 0.3259];
c = categorical({'Apples','Oranges','Bananas','Kiwi'});
bar(c,RSME)
RSMEref = [0.0191 0.0383 0.0765 0.1148 0.1530;
0.0176 0.0352 0.0705 0.1057 0.1410;
0.0139 0.0279 0.0558 0.0837 0.1116;
0.0155 0.0311 0.0622 0.0933 0.1244];</pre>Aurejahttps://nl.mathworks.com/matlabcentral/profile/authors/5601490-aurejatag:nl.mathworks.com,2005:Question/3725692017-12-12T14:40:17Z2017-12-12T14:52:24Zplease i cant run my model due to problem in sample time <p>Derivative input 1 of 'untitledt/Control Circuit/PID Controller (with Approximate Derivative)/Integrator' at time 0.0051474852 is Inf or NaN. Stopping simulation. There may be a singularity in the solution. If not, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances)</p>Esraa Fayezhttps://nl.mathworks.com/matlabcentral/profile/authors/11619384-esraa-fayeztag:nl.mathworks.com,2005:Question/3697262017-11-28T13:28:39Z2017-12-12T14:50:05ZHOw to fix an Error in deep network configuration with images data sets<p>I have two correlated images data sets, I am trying to feed each dataset into (input1) and (input2) in a netwrok named (TestNet).
Iused imagedatastore twice to load the two data sets as following:</p><pre class="language-matlab">imds1 = imageDatastore (Path of data1, 'Includesubfolder', true, 'Labelsource', 'foldername');
</pre><pre class="language-matlab">imds2 = imageDatastore (Path of data2, 'Includesubfolder', true, 'Labelsource', 'foldername');
</pre><pre class="language-matlab">imds1.ReadFcn = @ (readDatastoreImage) readAndProcessImage (readDatastoreImage);
</pre><pre class="language-matlab">imds2.ReadFcn = @ (readDatastoreImage) readAndProcessImage (readDatastoreImage);
</pre><pre class="language-matlab">[Train1, Test1] = splitEachLabel (imds1, 0.7, 'randomize');
</pre><pre class="language-matlab">[Train2, Test2] = splitEachLabel (imds2, 0.7, 'randomize');
</pre><pre class="language-matlab">imds = {Train1; Train2}; % I found this in one of the questions/answers in mathwork (Trying to feed the network with the two inputs, one to layer 1 and 2nd to the layer 2)
</pre><pre class="language-matlab">Layers = [Inputlayer [28 28 3]
Conv1
maxpool1
Conv2
FC (10)
Softmax
Classification]
</pre><pre class="language-matlab">TestNet = network (2,7); % Define a custom network with 2 inputs and 7 layers.
</pre><pre class="language-matlab">TestNet.Inputconnect (1,1) = 1; % Trying to connect input 1 with layer 1
</pre><pre class="language-matlab">TestNet.Inputconnect (2,1) = 1; % Trying to connect input 2 with layer 2 (Is this right?)
</pre><pre class="language-matlab">TestNet = configure (TestNet, imds);
</pre><pre class="language-matlab">TestNet = trainNetwork (imds, Layers, options);
</pre><p>After Run, there is an error says Input data {1,1} is not numeric or logical / error using network/configure.</p><p>wish to hear from you genius</p>Mammo Imagehttps://nl.mathworks.com/matlabcentral/profile/authors/7663838-mammo-imagetag:nl.mathworks.com,2005:Question/3725102017-12-12T09:36:31Z2017-12-12T14:45:34Zrref,rank,transform matrix without using command rref and rank<p>rref,rank,transform matrix without using command rref and rank;someone help me please,thanks you so much</p>An Chanhttps://nl.mathworks.com/matlabcentral/profile/authors/11726410-an-chantag:nl.mathworks.com,2005:Question/3693842017-11-27T00:54:16Z2017-12-12T14:38:27Zglmfit optimization algorithm?<p>Hello, I'm trying to understand what optimization algorithm is used in the glmfit function to produce the output. I wanted to know if it uses least-squares method, numerical optimization, etc... (i.e. how the coefficients are updated such that the predicted value becomes closer to the actual value) Can you please let me know where I can find this information? Thank you!</p>Joonnyong Leehttps://nl.mathworks.com/matlabcentral/profile/authors/5497548-joonnyong-leetag:nl.mathworks.com,2005:Question/3721192017-12-10T03:11:45Z2017-12-12T14:36:11ZVectors Must be the Same Length<p>I want to plot this but the problem is that I need to somehow have the vectors be the same length.</p><pre class="language-matlab">Year=input('Enter the year ');
Hour=input('Enter the hour ');
Index=find(time(:,1)==Year & time(:,16)==Hour);
Max=max(time(Index,2:13))
Mean=mean(mean(time(Index,2:13)));
X=(1:365)';
Y=Max';
y=Mean*ones(1,365);
cla
hold on
plot(X,y,'b') %This plots the mean value with x.
plot(X,Y)
</pre><p>The objective is to plot max and mean when x goes from 1 to 365. Mean has to be a single line because it's a single value. Max has to be 12x365 and it should return only one value for each column but the problem is that when I run that code it gives me the error.</p><pre> Day=input('Enter the year ');
Year=input('Enter the hour ');
Index=find(time(:,1)==Year & time(:,16)==Hour);
Max=max(time(Index,2:13),1)
Mean=mean(mean(time(Index,2:13)));
X=(1:365)';
Y=Max';
y=Mean*ones(1,365);
cla
hold on
plot(X,y,'b') %This plots the mean value with x.
plot(X,Y)</pre><p>If I run the above code it works fine. It doesn't return any error. Now the problem with the second one is that it returns more than one value for each column and the plot shows different colors in the graph. I want it to show only one color and hopefully run the code which returns one value for each column for max.</p>Rafaelhttps://nl.mathworks.com/matlabcentral/profile/authors/11001304-rafaeltag:nl.mathworks.com,2005:Question/3693282017-11-26T16:12:14Z2017-12-12T14:32:25Zhow to use multiple input layers in DAG net as shown in the figure<p>I have DAG graph with two paths of layers inside it.</p><p>I am planning to feed this DAG with two types of data (D1, D2) but I can't do it as the DAG in matlab accept just one input layer.</p><p>I need to form a layer such as:</p><img src = "/matlabcentral/answers/uploaded_files/96195/ssssssss.PNG"><p>I noticed that there is a custom network that can provide a network with multiple inputs but how can I connect between this network and DAG graph? or how could I use DAG with two inputs?</p>Ben Hurhttps://nl.mathworks.com/matlabcentral/profile/authors/11342008-ben-hurtag:nl.mathworks.com,2005:Question/3725672017-12-12T14:30:25Z2017-12-12T14:30:25ZOrange OBAI check in Polyspace Code Prover R2015a<p>The code snippet below is verified with CodeProver R2015a. The tool detects an orange OBAI at line 11033 (iter [-2^31...2^31+1]). The variable iter is type unsigned int.</p><pre class="language-matlab">typedef uint8_least Dcm_TimerIdType;
</pre><pre class="language-matlab">typedef unsigned int uint8_least; /* At least 8 bit */
</pre><p>Nevertheless at line 11033 the tool says array index value: [ <b>-2^31</b>...2^31+1]???</p><img src = "/matlabcentral/answers/uploaded_files/98326/Code.png"><img src = "/matlabcentral/answers/uploaded_files/98328/Code2.png">Dimohttps://nl.mathworks.com/matlabcentral/profile/authors/2312439-dimo