http://www.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions20160827T01:26:13Ztag:www.mathworks.com,2005:Question/30025120160820T09:04:55Z20160827T01:26:13ZA problem about Gui<p>I write a gui program use the matlab 2015b，at the gui edit interface display as picture 1</p><img src = "/matlabcentral/answers/uploaded_files/58110/1.jpg"><p>.the control button is clearly。but change to the .exe file，the control button is not clearly as picture 2 shows.
Thanks！</p><img src = "/matlabcentral/answers/uploaded_files/58111/2.jpg">ren renhttp://www.mathworks.com/matlabcentral/profile/authors/7872723renrentag:www.mathworks.com,2005:Question/30103520160826T23:25:30Z20160827T01:16:00Zfprintf one data per cell from text to csv <p>Hi all,
I've written the following code to help me copy the third column from multiple text files to one csv spreadsheet in the following format: header is 'Trails', followed by third column of each text file displayed horizontally per row (thus no \n).</p><pre class="languagematlab">fidO = fopen('pvtsort.csv','wt');
d = dir('*txt');
for i = 1:length(d)
fid = fopen(d(i).name, 'r'); % open all input txt files, no array
values = textscan(fid,'%*s%*s%s','HeaderLines',4, 'Delimiter','\t');% read only the 3rd column
fprintf(fidO,'%s\t','Trails');
for j = 1:length(values{1,1})
pvt = values{1,1}
fprintf(fidO,'%s\t',pvt{j}); %note "the curlies" to dereference cellstr to char
end
fprintf(fidO,'\r\n')
fid = fclose(fid);
end
fidO = fclose(fidO)
</pre><p>Well the output looks fine when I open the csv in matlab, with one data point occupying one cell, one column of data per row with header "Trails" in front. However, when I open my output spreadsheet 'pvtsort.csv' directly outside matlab, it looks funny. All the data points from one column are crammed into a cell instead of separate cells like how the csv was displayed in matlab (as if the '\t' didn't work). I played around with several delimiters like \v, \r,combinations of these with '\t', but could not for the life of me figure out why data wasn't displayed properly when opening csv outside matlab.
Pointers appreciated.</p>Tammy Chenhttp://www.mathworks.com/matlabcentral/profile/authors/4892102tammychentag:www.mathworks.com,2005:Question/30103720160827T01:15:08Z20160827T01:15:08Zneural networks, MSE goal<p>Respected colleague</p><p>Would we perhaps be able to explain the term linked to neural networks
MSEgoal = 0.01*Ndof*MSE00a/Ntrneq.</p><p>This term is quite often seen in training neural networks , but it unfortunately is not completely clear for me.</p><p>I need a more detailed explanation of the term , maybe some references, example or just explanations.</p><p>Also on this occasion, I wish to thank Mr. Greg Heath for excellent explanations and tutorials . Mr Greg Heath explanations are much better than many that can be found in the available literature . Thank you very much for that .</p>Miljan Kovacevichttp://www.mathworks.com/matlabcentral/profile/authors/4313196miljankovacevictag:www.mathworks.com,2005:Question/12822120140504T15:17:33Z20160826T23:53:28ZWhy Matlab can't load initial states of a demo model after i copy it in my own model?<p>Hi
i want to use Wind Farm  DFIG Detailed Model inside my simulation.
this is what i do:
first i type power_wind_dfig_det in the command window, after i press enter the model appears.
then i copy the entire and paste it inside my own model.
i know that it needs initial states so i put the initial states file power_wind_dfig_det_xinitial in the working folder and set the Initial state=xInitial
(all files can be found here: C:\Program Files\MATLAB\R2013a\toolbox\physmod\powersys\DR\DRdemo )
but after i run the simulink i get this error:
Error loading the initial state for model 'MyModel'. Unable to find a matching block state corresponding to element 1 of signals structure array.</p><p>So the question is why Matlab can't load the initial states while it is available and loaded correctly into the workspace?</p>Mikehttp://www.mathworks.com/matlabcentral/profile/authors/3685780miketag:www.mathworks.com,2005:Question/30103620160826T23:34:07Z20160826T23:34:07ZReading column labels in a Matrix<p>I have a 65536x93 dataset with column labels which are numbers. I want to store the column labels in a 1x93 matrix with the labels as numbers which will be used as the xaxis in a plot.</p><p>Please help</p>Shiladitya Chatterjeehttp://www.mathworks.com/matlabcentral/profile/authors/6983150shiladityachatterjeetag:www.mathworks.com,2005:Question/30103420160826T22:37:12Z20160826T22:39:59Zhelp needed in cosine similarity method<p>Dear experts i want to implement cosine similarity method take an example
i have a matrix</p><pre class="languagematlab">[2 3 4 5 1;1 2 3 4 2;4 5 1 1 2]
</pre><p>i want to predict value now i will hide one of them and use this method so far i have coded cosine method like this</p><pre class="languagematlab">clc;
clear all;
close all;
load('Sample.mat');
load('Sample_Hidden.mat');
A=Sample;
B=Sample_Hidden;
</pre><pre class="languagematlab">C=cosineSimilarityNaive(A);
options = [];
options.Metric = 'Euclidean';
options.NeighborMode = 'KNN';
options.bNormalized=1;
options.k = 5;
options.WeightMode = 'Cosine';
</pre>abdul wahab azizhttp://www.mathworks.com/matlabcentral/profile/authors/7148942abdulwahabaziztag:www.mathworks.com,2005:Question/30103220160826T22:13:58Z20160826T22:30:05ZA question on Scatter PLot ???<p>Hello Everyone ,</p><p>I have two arrays of each [10000x2] size. First Column of Data is XAxis and Second Column is YAxis. Same goes with the Second Array too.
I need to have a moving scatter plot. i.e I need to see the Data being plotted ,point by point. I tried using for loop and plot point by point for a single graph But it hangs .... Finally I found an answer from mathworks guy who posted a solution. It did worked and I need to do a workaround to that solution so that I can plot two arrays like same. <b>*************************************************</b></p><pre class="languagematlab">V1 = rand(1,10000);
V2 = rand(1,10000);
N = NaN([1,10000]);
h = scatter(N, N , 'r*');
xdata1 = get(h, 'XData');
ydata1 = get(h, 'YData');
for lk = 1:10000
xdata1(lk) = V1(lk,1);
ydata1(lk) = V1(lk,2);
% Update the plot
set(h, 'XData', xdata1, 'YData', ydata1);
drawnow
end
***************************************************
</pre><p>If you execute this code, you will be seeing some points being plotted oneby one..
Now I need the V2 plot on the same figure with different color marker.. like for black asterisk 'k*' .. I am not sure how to workaround by having a same figure handle with two different markers... Do u have any suggestions. ?</p><p>This is for analyzing the GPS location tracks .. So need it it MATLAB instead of Google Earth(KML)</p>A P Shttp://www.mathworks.com/matlabcentral/profile/authors/4801875apstag:www.mathworks.com,2005:Question/30103320160826T22:17:55Z20160826T22:17:55ZMultiple integration for multiple variables of chain of functions<p>I am trying to write a code where I have following:</p><p>B1 is a function of (s,q,xp) where B(s,q)= integration of B1 along xp.</p><p>A1 is a function of(s,q,zp,dk) where A(s,q) = integration of A1 along zp and dk.</p><p>W1(s,q,x) = exp(A)*B*exp(i*q*x) then W(s,x) = integration of W1 along q</p><p>The last function is swept for different x and s</p><p>I tried different approaches, but I dont seem to get the right method.</p>mahd batarsehhttp://www.mathworks.com/matlabcentral/profile/authors/2730979mahdbatarsehtag:www.mathworks.com,2005:Question/30103120160826T22:05:49Z20160826T22:05:49ZHow can I resolve ELF file OS ABI invalid errors when starting license manager daemon on older OS?<p>I have an older Linux operating system hosting my license manager daemon. Upon startup, I receive several of the following error message:
MLM: error while loading shared libraries: /mathworks/etc/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: ELF file OS ABI invalid</p><p>The MLM process eventually exists with a nonzero status:
88 14:48:29 (lmgrd) MLM exited with status 127 ()
89 14:48:29 (lmgrd) Please correct problem and restart daemons</p><p>I am not able to update the OS on this system.</p><p>Is there a way I can move forward without changing the license server's OS?</p>Jeffhttp://www.mathworks.com/matlabcentral/profile/authors/8476996jefftag:www.mathworks.com,2005:Question/30103020160826T21:58:54Z20160826T22:04:20ZProfessor Plotted; plot(x,y,'o',x,m*x+b) I want to plot the same thing just using m*x^3+b<p>I have tried to use m*x.^3+b but my image looks like this....</p><img src = "/matlabcentral/answers/uploaded_files/58402/Capture.PNG"><p>here is the code my professor used,</p><pre class="languagematlab">N = length(x);
A = [x ones(N,1)];
for ix=1:N
A(ix,:) = [x(ix) 1];
end
p = (A'*A)\(A'*y);
m = p(1)
b = p(2)
xlabel('x');
ylabel('y');
plot(x,y,'o',x,m*x+b)
</pre><p>Why cant I just use the same thing and then type</p><pre class="languagematlab">plot(x,y,'o',x,m*x.^3+b) ?

</pre><p>The original question asks for an estimate of m and b coefficients using least squares with a fit model y = mx^3+b.</p><p>I don't just want working code for my problem. I really want to understand whats going on in his code and learn how to plot a cubic fit using that model.</p>Dustin Braunhttp://www.mathworks.com/matlabcentral/profile/authors/8583843dustinbrauntag:www.mathworks.com,2005:Question/30101820160826T18:16:10Z20160826T21:48:05ZAlternative to ginput for selecting data from an image?<p>I've got an image with pixels that are 0.1 units in x and 0,1 units in y. I want to have a user select some number 'n' points on that image and assign the x,y coordinates of those selections to a variable. I have tried to use "ginput" to do this, but there is one issue. When using ginput, if I click in the pixel (1.1, 3.2), for example, I might get values of (1.12034, 3.259034) when what I want is (1.1, 3.2). If I use the data cursor, it provides (1.1, 3.2) but I don't know how to automatically get those values into a variable.</p><p>I suppose I could round the coordinates down to the nearest 0.1, but the pixel size will not always be the same and I'd prefer to have a slightly more elegant solution. Is there another function similar to ginput that provides the x,y values of a point in the same way that the datacursor does?</p><p>Thanks!</p>Emmahttp://www.mathworks.com/matlabcentral/profile/authors/3657523emmatag:www.mathworks.com,2005:Question/30102920160826T21:35:47Z20160826T21:36:22ZHow to implement conditional compilation using simulink coder <p>I have a rather large model that takes an hour to compile in it's entirety. This question has been asked before, but the links are broken that were provided as an answer. The aim would be to only build the portion of the model that changed, just like in hand coded applications.</p>Thomas Justhttp://www.mathworks.com/matlabcentral/profile/authors/8387434thomasjusttag:www.mathworks.com,2005:Question/30093020160825T23:44:51Z20160826T21:25:03Zhow to reset the axes in this situation of my GUI?<p>i tried everything i could find, but no clue how to do it !</p><pre class="languagematlab">function varargout = CST(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @CST_OpeningFcn, ...
'gui_OutputFcn', @CST_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
</pre><pre class="languagematlab">if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code
</pre><pre class="languagematlab">%  Executes just before CST is made visible.
function CST_OpeningFcn(hObject, ~, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
</pre><pre class="languagematlab">function varargout = CST_OutputFcn(~, ~, handles)
varargout{1} = handles.output;
</pre><pre class="languagematlab">function a_Callback(~, ~, ~)
</pre><pre class="languagematlab">function a_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
</pre><pre class="languagematlab">function d_Callback(~, ~, ~)
</pre><pre class="languagematlab">function d_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
</pre><pre class="languagematlab">function N_Callback(~, ~, ~)
</pre><pre class="languagematlab">function N_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
</pre><pre class="languagematlab">function dz_Callback(~, ~, ~)
</pre><pre class="languagematlab">function dz_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
</pre><pre class="languagematlab">function b_Callback(~, ~, ~)
</pre><pre class="languagematlab">function b_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
</pre><pre class="languagematlab">function c_Callback(~, ~, ~)
</pre><pre class="languagematlab">function c_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
</pre><pre class="languagematlab">function e_Callback(~, ~, ~)
</pre><pre class="languagematlab">function e_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
</pre><pre class="languagematlab">function f_Callback(~, ~, ~)
</pre><pre class="languagematlab">function f_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
</pre>oussama souadkahttp://www.mathworks.com/matlabcentral/profile/authors/7219840oussamasouadkatag:www.mathworks.com,2005:Question/30009020160818T20:48:26Z20160826T21:07:40Zconvert the time domain signal into frequency domain signal<p>Hi,
I have represented the acceleration data of 3 axes(x, y, and z) in time domain as shown in the Graph</p><img src = "/matlabcentral/answers/uploaded_files/58057/neamah.jpg"><p>I would like to extract from the acceleration data some measurements (e.g. mean, energy, entropy and correlation) in the frequency domain. Therefore, I applied <b>FFT</b> transform in order to convert the time domain signal into frequency domain signal.</p><pre> xx= fft(x_Segments{1});
plot(xx)
yy= fft(y_Segments{1});
plot(yy)
zz= fft(z_Segments{1});
plot(zz)</pre><p>However, the resulted graphs make no sense( so strange) which is not expected at all !!
This is an example of the frequency domain signal of the xaxis.</p><img src = "/matlabcentral/answers/uploaded_files/58058/fft.jpg"><p><b>Note, x_Segments, y_Segments, and z_Segments contain the data of X, Y, Z axes respectively</b></p><p>As we can see the graph doesn't make sense, so, is there any steps that I should follow before using the FFT function to get the expected frequency domain signal?</p><p>I really appreciate your help guys.
thanks</p>neamah alnaffakhhttp://www.mathworks.com/matlabcentral/profile/authors/7635969neamahalnaffakhtag:www.mathworks.com,2005:Question/30102720160826T20:53:52Z20160826T20:53:52ZInclude .prj file in version control without build causing dirty repo<p>I have a matlab application under version control using git. The current problem is that every time I build the executable, the build checksum in the .prj file changes, and so my repository is no longer clean. I need the prj file in the repository since I can't create it from scratch using code.</p><p>Any suggestions?</p>Trogdorhdhttp://www.mathworks.com/matlabcentral/profile/authors/2968990trogdorhdtag:www.mathworks.com,2005:Question/30102620160826T20:45:51Z20160826T20:48:25ZNeed to fix a "All sample times for this block must be discrete."<p>I'm getting an error with a reference model that I converted from a subsystem. The reference model uses the Comm Simulink library block "CPM Modulation Baseband". The error is "
Error using sweep_modulations_mod (line 118) Error in 'Modulator1a/CPM Modulator Baseband': All sample times for this block must be discrete. No continuous or constant sample times are allowed."</p><p>Within Modulator1a, I've set the solver parameters: "Solver" to "discrete..." and the "Type" to "fixedstep."</p>Charlie Simmonshttp://www.mathworks.com/matlabcentral/profile/authors/8444577charliesimmonstag:www.mathworks.com,2005:Question/30102520160826T20:42:52Z20160826T20:42:52ZRunning m files repeatedly<p>Hello,
I have an MATLAB script called basicscript.m which is a modified version of the neural network pattern recognition tool pattern.net. The network works fine with my input and target data. I want to repeatedly run the script with the same input and target data to observe changes in the perfomnace (e.g trainperf etc) as the weights are randomised each time the script is run.
Ideally, I want to be able to
1. Load the script up with my input and target data once.
2. Repeatedly run the script with the same data by simply pressing a key (say 'C') on the keyboard without having to load the same data each time which is cumbersome.
Is there a way to do this in MATLAB without having to load the same data each time.
Thanks in advance
Chris Bishop</p>Christopher Bishophttp://www.mathworks.com/matlabcentral/profile/authors/4866992christopherbishoptag:www.mathworks.com,2005:Question/30087920160825T14:41:20Z20160826T20:42:07ZHow can the default properties of a SimBiology model diagram be changed?<p>Is it possible to change the default properties of a SimBiology diagram? e.g. arrow widths, font size in blocks, etc.</p><p>Related: is it possible to change these properties in an existing diagram all at once?</p>Colin Phippshttp://www.mathworks.com/matlabcentral/profile/authors/8143318colinphippstag:www.mathworks.com,2005:Question/30102420160826T20:34:55Z20160826T20:36:50Zhi, i want partition largest interval(contain more than element) to 4 interval , and partition the second biggest interval to 3 interval,and partition the third biggest interval to 3 interval, But the rest remains the same.retaining orderofinterval <p>% i have n values z1,z2 , ...,zn this is numerical values . i partition this to seven interval as following and calculate the length for every interval(length for nonzero element), the interval contain more than element from z1,...zn i need partition it to 4 subinterval have same length While retaining the order and the second largest interval partition to 3 subinterval have same length and the third interval partition to 2 subinterval have same length and the remaining interval Remain the same . In the end we get to 13 interval .</p><pre class="languagematlab">n = 50;
z = 1000 * rand(1, n); % Sample data
a=min(z);
b=max(z);
k =7; % such that k is the number of intervals
L= (max(z)min(z))/k; %such that L is length of each interval
% Here is my solution:
intK = round(k);
uMatrix = [linspace(a, bL, intK)', linspace(a+L, b, intK)']
for i=1:n
for j=1:k
if (uMatrix(j,1)<=z(i)&z(i)<=uMatrix(j,2))
uMatrix(j,1,i)=z(i);
end
end
end
for i=1:k
temp1=uMatrix(i,:,:);
%whos temp1
temp2 = nonzeros(temp1);
%whos temp2
temp3 = length(temp2);
%w hos temp3
le(i)=temp3;
end
</pre>mohammed elmenshawyhttp://www.mathworks.com/matlabcentral/profile/authors/8517451mohammedelmenshawytag:www.mathworks.com,2005:Question/30102320160826T20:32:39Z20160826T20:32:39ZHow can I use a equation solve function (solve/fzero/ect.) as the first input of Double Integral Function (integral2) ?<p>In Matlab, the first input of Double Integral Function (integral2) should be a function handle. But in my application, I need to use the root of x,y equation as the first input.</p><p>Part of the code is attached below:</p><p>(Mindex,fc,fo are fixed number)
yr1 = @(x) pi/2.*(Mindex.*sin(x)+1);
yf1 = @(x) pi/2.*(Mindex.*sin(x)+1);
x1 =pi;
x2 =pi;
Magn_r= @(x,y) (xfzero(@(x0) fc.*yfo.*x+fc.*pi./2.*(Mindex.*sin(x0)+1)+fo.*x0,0));
fun = @(x,y) Magnitude_Sw(x,y).*exp(i*(m.*y+n.*x));
Y=integral2(fun,x1,x2,yr1,yf1,'AbsTol',1e3,'RelTol',1e2);</p>Yingzhuo Chenhttp://www.mathworks.com/matlabcentral/profile/authors/7298639yingzhuochentag:www.mathworks.com,2005:Question/30102220160826T20:20:40Z20160826T20:20:40ZOne or more MuPAD fonts are missing. Typesetting may be corrupted<p>"One or more MuPAD fonts are missing. Typesetting may be corrupted"</p><p>That is the message I get as I start MuPad. And my files are not readable at all! Anybody knows a fix ?</p>JJMhttp://www.mathworks.com/matlabcentral/profile/authors/1163271jjmtag:www.mathworks.com,2005:Question/30101020160826T16:07:10Z20160826T20:17:04ZHow can I show spheres "rolling" around in animation?<p>Hello everyone,</p><p>I am generating a visual of spheres "bouncing" around like soccer balls. Reference the animations in the ZIP file and the code. I am able to plot the spheres using the "sphere" function. However, I do not know how to visualize the rotation. Is there a way to color the spheres such that it is easy to see it rotate? Also, what would be a good way to apply the rotation to the sphere? Thanks.</p><p>Best regards,</p><p>Bill Rooker</p>Bill Rookerhttp://www.mathworks.com/matlabcentral/profile/authors/189816billrookertag:www.mathworks.com,2005:Question/29997020160818T06:11:19Z20160826T20:14:12Zreset(gpuDevice) does not work<p>When I run the following code for values of n<5000 it runs just fine.</p><pre class="languagematlab">reset(gpuDevice);
</pre><pre class="languagematlab">n=5000;
</pre><pre class="languagematlab">a=gpuArray(rand(n));
</pre><pre class="languagematlab">b=gpuArray(rand(n));
</pre><pre class="languagematlab">tic
</pre><pre class="languagematlab">t=a'*a;
</pre><pre class="languagematlab">c=t\(a*b');
</pre><pre class="languagematlab">toc
</pre><p>But when I run it for n=5000 i get the error "Error using \ Call to Double LU on GPU failed with error status: unspecified launch failure."</p><p>If I try running the program again for any small value of n I get the error</p><p>"Error using parallel.gpu.CUDADevice/reset</p><p>An unexpected error pccured during CUDA execution. The CUDA error was " all CUDA capable devices are busy or unavailable"</p><p>Also, if I execute the following command</p><pre class="languagematlab">g=gpuDevice;
disp(g.FreeMemory)
</pre><p>I get the answer to be NAN</p><p>I am unable to run the reset(gpuDevice) command. It gives the same error as above.</p>Renu Dhadwalhttp://www.mathworks.com/matlabcentral/profile/authors/3158252renudhadwaltag:www.mathworks.com,2005:Question/30101720160826T18:10:27Z20160826T20:05:20ZI am having problems installing MATLAB on my computer<p>I have tried to install the MATLAB software on my computer, version R2015b (9.0)*, 32 bit. The 64 bit version will not work, since I am using Windows 7, 32 bit. As I go through the installation, the files are unzipped ok, but then I get a message "The system cannot find the file specified", and then immediately quits without providing any additional information about the missing file. How can I find the correct file that the installer is missing, and make sure that it is included? Thanks in advance for any responses.</p>Paul Bermanhttp://www.mathworks.com/matlabcentral/profile/authors/8600213paulbermantag:www.mathworks.com,2005:Question/30102020160826T19:31:31Z20160826T20:03:22Zwhat is the difference between one class learning and two class learning?<p>On <a href = "http://www.mathworks.com/help/stats/classificationsvmclass.html">this</a> link, it says about one class and twoclass learning.</p><p>I don't understand one class learning. If there is only one class then why learning is required?</p><p>I understand that binary classification is two class learning.
Can anyone explain me what is one class learning?</p>KJVKU999http://www.mathworks.com/matlabcentral/profile/authors/1773785kjvku999tag:www.mathworks.com,2005:Question/30097220160826T10:01:33Z20160826T23:20:16ZHow can I plot the graph in the figure?<pre class="languagematlab">a= 5;
b= 10;
c= 4;
T=a+b;
t=100:1:100;
for k= 1 : length(t)
if t(k)<=b
f0(k)= ((1).^c).*(a+b);
else if t(k)>b && t(k)<=(b+a)
f0(k)= ((1).^b).*(a);
else if t(k)>(b+a)
f0(k) =0;
else if t(k)<0
f0(k)=0;
end
end
plot(t,f0);
f = zeros(size(t));
for k=1:5
for i=1:length(t)
f(i) = f0(i  k.*T) + f(i);
end
end
figure
plot(t,f)
</pre><p>figure()
plot(t,abs(f))
figure()
plot(t, angle(f0))
end<<</p><img src = "/matlabcentral/answers/uploaded_files/58372/New%20Bitmap%20Image.png">Mujtaba Husseinhttp://www.mathworks.com/matlabcentral/profile/authors/5819885mujtabahusseintag:www.mathworks.com,2005:Question/30102120160826T19:51:51Z20160826T19:51:51ZHow to tell matlab to automatically use all available cores  Matlab 2012<p>Hi, I am using Matlab 2012 on different machines  my work computer and my home computer. Both machines have different number of cores. I use parallel computing to speed up some parts of the computation and I'd like to adapt my code so that it would use the max number of cores on a machine.</p><p>For my work machine, I type in "matlabpool open local 8" whereas for my home machine I type in "matlabpool open local 2".</p><p>May I know how I can modify this code so that I can run the same code on both machines without manually having to change the maximum number of workers used?</p><p>Thanks!</p>Isaachttp://www.mathworks.com/matlabcentral/profile/authors/6596049isaactag:www.mathworks.com,2005:Question/30075220160824T14:58:04Z20160826T19:46:37ZCompare block does not work!<p>I have a Simulink Model built in Matlab/Simulink 2012 and it works perfectly, however if I run the model in newer Simulink 2015, the compare blocks does not output a continuous signal to the Scope? (I have to set the scope marker but it shows discrete points)</p><p>Am using the exact same model (and settings) in both Matlab versions.</p>ALZhttp://www.mathworks.com/matlabcentral/profile/authors/3664962alztag:www.mathworks.com,2005:Question/30099520160826T13:19:24Z20160826T19:35:42Z[SIMULINK] Increment a variable<p>Hi everyone,</p><p>I have a problem in Simulink, I have a variable "k" as constant Block (start Value k =1 ) and i would like to increment "k" after every Time i simulate my Modell untill k=4 then should k reset to 1</p><p>i will apreciate any Help many thanks Jay</p>Jay Saminhttp://www.mathworks.com/matlabcentral/profile/authors/8462844jaysamintag:www.mathworks.com,2005:Question/30039620160822T03:56:17Z20160826T19:34:33Zhow can i creat image from data?<p>hi I'm beginner in matlab my problem is how to get image.i have text data (row,col) and i want to create image from this data, and this image should be like fringes (dark and white line)</p>Sanaa http://www.mathworks.com/matlabcentral/profile/authors/7679805sanaatag:www.mathworks.com,2005:Question/30100320160826T15:02:53Z20160826T19:02:51ZPre allocating all fields in a structure?<p>I have several structures that can have variable sizes and must handle a large amount of data of various types. Each structure may have 25 or more fields.
I want to preallocate these structures but all the solutions I found preallocate each structure field individually.
pseudo code example:</p><pre class="languagematlab">mystructure.a = preallocate; % using your favorite method
mystructure.b = preallocate;
....
etc.
</pre><p>Since I have so many fields and multiple structures this becomes rather cumbersome.
Is there a way to preallocate <b>all</b> the fields in the structure in one line?
Example:</p><pre class="languagematlab">mystructure.all the fields = preallocate; % using your favorite method
</pre><p>Thank you in advance</p>HRmatlabhttp://www.mathworks.com/matlabcentral/profile/authors/122458hrmatlabtag:www.mathworks.com,2005:Question/30080320160824T22:11:37Z20160826T18:59:25ZHi, In Configuration Parameters, Code style I have selected th option to Convert ifelseifelse to switch case statements but the generated code still generates the code using if else. How to make sure it generates using switch case?<p>Hi,</p><p>I am trying to generated code for a stateflow Flowchart, In Configuration Parameters, Code style I have selected th option to Convert ifelseifelse to switch case statements but the generated code still generates the code using if else. How to make sure it generates using switch case?</p>Harish Shekarappahttp://www.mathworks.com/matlabcentral/profile/authors/8473320harishshekarappatag:www.mathworks.com,2005:Question/30055620160823T06:26:25Z20160826T18:57:28ZODE15s error: First argument must be a singlequoted string <p>Hi, I am new to Matlab and I am trying to use ode15s function by running the example code given as ODEs with single solution component <a href = "http://www.mathworks.com/help/matlab/ref/ode15s.html">http://www.mathworks.com/help/matlab/ref/ode15s.html</a>. The script I am running is as follows:</p><pre class="languagematlab">tspan = [0 2];
y0 = 1;
[t,y] = ode15s(@(t,y) 10*t, tspan, y0);
plot(t,y,'o').
</pre><p>This script seems to be the same as the example, yet I am receiving the following error:
First argument must be a singlequoted string. See ODE15S.</p><p>Can anyone help me solve this problem?</p><p>Thank you</p><p>Ardi</p>Ardic Arikalhttp://www.mathworks.com/matlabcentral/profile/authors/8431046ardicarikaltag:www.mathworks.com,2005:Question/30101920160826T18:49:36Z20160826T18:49:36ZHow to minimize phase? any filter ?or algorithm?<p>I have a graph of phase v/s frequency..... and i have to design a filter in order minimize the phase to almost zero.
Please can anyone provide me help?</p>L Khttp://www.mathworks.com/matlabcentral/profile/authors/8487281lktag:www.mathworks.com,2005:Question/30099220160826T12:56:31Z20160826T18:40:17ZMatlab 6.5 on Windows 10<p>I have installed version 6.5 on windows 10 and given full access permission to the folder(i have created folder MATLAB6p) however finding difficult to open.I know this is an old version but due to some old coding which need to be run on this version.Please guide.
Advance thanking.</p><p>regards</p>Ana Roycehttp://www.mathworks.com/matlabcentral/profile/authors/7133000anaroycetag:www.mathworks.com,2005:Question/30092320160825T22:13:02Z20160826T18:33:11ZRBF newrb, array exceeds maximum size<p>My input dataset is 13x778162 large. I tried to create RBF network by newrb, but I got error: <i>Error using zeros
Requested 778162x778162 (4511.6GB) array exceeds maximum array size preference.</i> My RBF network:</p><pre class="languagematlab">eg = 0.1; % sumsquared error goal
sc = 0.2; % spread constant
mn = 10; % maximum number of neurons
df = 1; % number of neurons to add between displays
net = newrb(input,target,eg,sc,mn);
</pre><p>Using all 778162 neurons is too much, I understand. But I use function <i>newrb</i>, so I thought, that I can set maximum number of neurons by parametr <i>mn</i>, which is set to 10 neurons, but matlab still uses too much space.</p>EdWoodhttp://www.mathworks.com/matlabcentral/profile/authors/7976091edwoodtag:www.mathworks.com,2005:Question/29764520160729T10:01:35Z20160826T18:15:57Zabout using 'visual studio 2015 community' for compiler when we use 'mex' of command<p>when I use the command 'mex setup', the error happen
the error is
「MEXはC言語のコンパイルに'Microsoft Visual C++ 2015 Professional (C)'を使用するように設定されています。」
Now my computer is installed「Visual studio 2015 community」
I want to use this for compiler.
Can I use this for compiler?
Could you tell me how I use 'Visual studio 2015 community' for compiler?
If I cannot use community for compiler, can you tell me the other free Visual studio that I can use for compiler?</p>tsujihttp://www.mathworks.com/matlabcentral/profile/authors/8479084tsujitag:www.mathworks.com,2005:Question/30092520160825T22:56:25Z20160826T18:15:35ZAdditional line types beyond , , ., and : ?<p>Is there a way to get additional line types beyond the basic 4 of solid, dashed, dashdot, and dot? Dot comes out very small in some graphs, and if you need to provide someone a graph that will be copied in black and white, you really have only the first three options!</p><p>Thank you.</p><p>Doug Anderson</p>Douglas Andersonhttp://www.mathworks.com/matlabcentral/profile/authors/3217998douglasandersontag:www.mathworks.com,2005:Question/30101320160826T17:24:39Z20160826T18:13:05ZHow do I read an excel file and plot graphs?<pre class="languagematlab">fileName = 'test.xls';
a=xlsread(fileName);
</pre><p>These commands are not working for me. Can anyone help? I get an error that the file not found.</p>L Khttp://www.mathworks.com/matlabcentral/profile/authors/8487281lktag:www.mathworks.com,2005:Question/30101620160826T18:09:42Z20160826T18:12:10ZDFT spectrum, phase and abs<p>See the defined sequence for 0<n< 30 and</p><p>x(n)=n</p><p>Graphic trends and its DFT in terms of magnitude and phase and discuss the results to vary
of the length of DFT</p>Lorenzo De Tomasihttp://www.mathworks.com/matlabcentral/profile/authors/8571860lorenzodetomasitag:www.mathworks.com,2005:Question/30092920160825T23:39:42Z20160826T18:04:25ZAdd zero rows to a matrix<p>Hi,
I have the matrix A:</p><pre class="languagematlab">A=[1 5;
2 4;
4 9;
6 3;]
</pre><p>All the elements of the 1st column are integer and arranged ascendingly but there is a jump somewhere (from row 2 to 4 missing 3 and from 4 to 6 missing 5).
I want to add zero rows wherever there is jump in the 1st column to become:</p><pre class="languagematlab">A=[1 5;
2 4;
0 0;
4 9;
0 0;
6 3;]
</pre><p>Thanks in advance</p>Ismaelhttp://www.mathworks.com/matlabcentral/profile/authors/1344148ismaeltag:www.mathworks.com,2005:Question/30101520160826T17:52:12Z20160826T17:52:12ZGenerate code from polyphase decimator <p>Hi,</p><p>I'm trying to generate code for a sample rate conversion to use on an embedded ARM Cortex M0+ Processor. If I would construct the SRC manually, there would be two interrupt routines: one on the high frequency with calculates one of the subfilter for the new sample and one on the low frequency wich adds the correct outputs of the subfilter for the new Sample.</p><p>Since I just need downsampling with factor 10, I create a MATLAB dsp.FIRDecimator object. But when I try to use the codegenerator it requires in the function an input vector with M (decimation factor) samples. Do I have to calculate the decimation in one function call? This would result in a longer latency and one big calculation block (every M input samples) wich will be very fragmented by interrupts. Is a different implementation available?
And is there a decimator implementation with WDF? Since the M0+ is no number cruncher every bit of performance gain is welcome...</p><p>Best Regards,
Wolfgang Birnbacher</p>Wolfgang Birnbacherhttp://www.mathworks.com/matlabcentral/profile/authors/8599747wolfgangbirnbachertag:www.mathworks.com,2005:Question/30101420160826T17:44:30Z20160826T17:44:30ZHow to cite identification toolbox documentation in a paper?<p>How to cite identification toolbox documentation in a paper in APA or other format?</p>MJhttp://www.mathworks.com/matlabcentral/profile/authors/3733997mjtag:www.mathworks.com,2005:Question/30099920160826T14:18:07Z20160826T17:42:17ZGet indeces of any quantile of a column<p>Hello everybody,</p><p>as of now I´m trying to sort a large (101x1168) matrix. I am always sorting the first column, on which the following three columns depend upon. I want to be able to get any of the indeces of, for example the top 10 % cent of the values, or the values between the .3 and .4 quantile of the first column, to adress those with a function. As of now I have used several sortrows(), but it takes a long time to run. It is important to know that the length of the columns may vary ( Some of the columns have more NaNs than others) and thus it would be amazing if it was a function that ignores NaNs (maybe a combination of quantile() and find()?)</p><p>Here an example of what I need:</p><p>Col. 1 Col. 2 Col. 3 Col. 4</p><p>15 18 12 32</p><p>14 23 19 12</p><p>10 7 18 12</p><p>9 34 12 13</p><p>11 19 3 17</p><p>I know want to know the Index and the value of the top 20% values a in the first column. In this case it would be 1. and 15. If implemented correctly I would be able to get a vector output with all the data.</p><p>Any help is truly appeciated!
Many thanks and kind regards,
A.Goe</p>A. Goehhttp://www.mathworks.com/matlabcentral/profile/authors/7458568agoehtag:www.mathworks.com,2005:Question/30100720160826T15:12:31Z20160826T17:34:15ZTotally crazy behaviour of figures. Axes going around through the image!<p>Hello,</p><p>I'm working on a GUI in matlab and I ended up with a really strange behaviour in my code. I manage to isolate the problem in a single script, which is the following:</p><pre class="languagematlab">fig = figure('Name','Spatial modes', ...
'numbertitle', 'off', ...
'ToolBar', 'none', ...
'menu','none','units','normalized',...
'outerposition',[0 0 1 1]);
title('whatever')
</pre><pre class="languagematlab">for i = 1:100
set(0,'CurrentFigure',fig)
cla
imagesc(rand(10))
caxis auto
hand.im_caxis.val = caxis;
</pre><pre> colormap hot
colorbar
axis ij equal tight
set(gca,'color','none')
title(num2str(i))
drawnow
pause(0.1)
end</pre><p>If you try to run it, you will see that the axes of the figure shift to the right every time the image is updated. After a dozen of shifts, they start shrinking until they are invisible and eventually they go back to the original size.</p><p>What is going on? What am I missing?</p><img src = "/matlabcentral/answers/uploaded_files/58387/strange.gif">Alessandro Masullohttp://www.mathworks.com/matlabcentral/profile/authors/3265833alessandromasullotag:www.mathworks.com,2005:Question/30100920160826T16:00:28Z20160826T17:27:55ZBest to represent two large data sets in one plot<p>Hi everyone,</p><p>I am dealing with a scatter plot on which I'd like to plot two data sets containing at least 1500 dots per dataset. This number can reach 10000.</p><p>So far I am plotting those points by using a scatter plot:</p><img src = "/matlabcentral/answers/uploaded_files/58389/ratio%20comp_XZ_YZ_SCATTER.png"><p>Do you think Matlab offers a better way to show my data?</p><p>Thank you,
Flo</p>Flohttp://www.mathworks.com/matlabcentral/profile/authors/8051880flotag:www.mathworks.com,2005:Question/9417020100729T16:54:00Z20160826T17:16:50ZHow can I reverse the yaxis when I use the IMAGE or IMAGESC function to display an image in MATLAB?<p>I execute the following commands to display an image using the IMAGESC function:</p><pre class="languagematlab">load clown
</pre><pre class="languagematlab">clims = [10 60];
</pre><pre class="languagematlab">imagesc(X,clims)
</pre><pre class="languagematlab">colormap(gray)
</pre><p>The yaxis runs from the top of the image to the bottom. I would like to reverse the yaxis so that it starts at the bottom of the image and runs to to the top.</p>MathWorks Support Teamhttp://www.mathworks.com/matlabcentral/profile/authors/4622813mathworkssupportteamtag:www.mathworks.com,2005:Question/17048020150119T04:21:30Z20160826T17:14:08Zparfor loop does not work properly<p>Currently I am running parallel computing on my 4cores iMac. I found no matter how many workers matlab connect to (for example, 4 workers), at some point workers will stop for very long time during calculation. (~1h) Then they will continue to work. This really slows down the speed of calculation. I checked Cpu usage, which is always around 50%. Also my iMac has very large memory(4*8 GB) and I allocate 8 Gb to Matlab in preference. Can anyone tell what happened here? My matlab version is 2014b (8.4.0.150421) 64bit (maci64). Thanks a lot!</p>Jingchen Fenghttp://www.mathworks.com/matlabcentral/profile/authors/6075331jingchenfengtag:www.mathworks.com,2005:Question/30101120160826T16:31:03Z20160826T17:13:34ZIf A is a matrix, A(:) produces the columns in a vector. Is there a parallel function for rows?<p>A=[1,2,3;4,5,6;7,8,9]. Then A(:) returns [1;2;3;4;5;6;7;8;9]. Is there an operator that will produce [1,2,3,4,5,6,7,8,9]?</p>Rajmohanhttp://www.mathworks.com/matlabcentral/profile/authors/5207884rajmohantag:www.mathworks.com,2005:Question/30101220160826T16:47:27Z20160826T16:47:27ZVPA > While converting from 'sym': The conversion returned a value of class 'matlab.mixin.Heterogeneous', which cannot be inserted into an array of class 'matlab.graphics.illustration.ColorBar'.<p>Hi,</p><p>This interesting error is caused from the following code:</p><pre class="languagematlab">x0 = [.1, .1];
options = optimoptions('fsolve','Display','iter');
dt=0.01;
Nt=0.1/dt+1;
Tarray = [0:dt:0.1];
T = 0;
for nt=1:Nt
T=T+dt;
X = sym('x', [1,2]);
F = torder1(X,T);
sols = vpasolve(F, X);
h(nt) = sols.x1;
theta(nt) = sols.x2;
end
for nt=1:Nt
plot(Tarray,h(nt),'*')
hold on
plot(Tarray,theta(nt),'+')
end
</pre><p>This uses below function</p><pre class="languagematlab">function F=torder1(x,T)
x_1=[0:0.01:1];
b=0.6;
clear x_1;
syms x_1 h theta
kappa =1;
</pre><pre> f_11 = 1( (h+(x_1b)*theta)^2/(h+(x_1b)*theta1*x_1*(1x_1))^2 );
f_21 = (x_1b)/2*( 1( (h+(1b)*theta)^2/(h+(x_1b)*thetax_1*(1x_1))^2 ));</pre><pre> fint_1 = int(f_11, x_1);
fint_2 = int(f_21, x_1);</pre><pre> x_1=1;
upper_1=subs(fint_1);
upper_2=subs(fint_2);
clear x_1;
x_1=0;
lower_1=subs(fint_1);
lower_2=subs(fint_2);
clear x_1;
integral_1old=upper_1lower_1;
integral_2old=upper_2lower_2;</pre><pre> h0 = kappa *b*(1b);
theta0 = kappa*(12*b);</pre><pre> integral_1 = subs(integral_1old, {h, theta}, {x(1), x(2)});
integral_2 = subs(integral_2old, {h, theta}, {x(1), x(2)});</pre><pre> F = [vpa(x(1)  integral_1*T^2 h0); vpa(x(2)  integral_2*T^2  theta0)];</pre><p>I know the error is related to the index of my for loop (nt).</p><p>Any help will be appreciated. Thanks.</p>Mevahttp://www.mathworks.com/matlabcentral/profile/authors/4934134meva