http://de.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2015-09-01T20:20:40Ztag:de.mathworks.com,2005:Question/2388212015-09-01T20:20:40Z2015-09-01T20:20:40Z Binomial coefficients with a twist: How could I write this in Matlab?<p>Hi,</p><p>Here is an algorithm someone suggested me to use in order to generate binomial coefficients but with a specific constraint.</p><p>First, the pseudocode:</p><pre class="language-matlab">combs(index,multiset,k,result):
if length of result == k:
output result
return
if length of result + length of multiset - index < k:
return
for j in multiset[index]:
combs(index + 1,multiset,k,result with multiset[index][j] added)
combs(index + 1,multiset,k,result)
</pre><p>Then, the person gave me a JavaScript example:</p><pre class="language-matlab">function combs(i,multiset,k,result){
if (result.length == k){
console.log(result);
return;
}
if (result.length + multiset.length - i < k)
return;
for (var j=0; j<multiset[i].length; j++){
_result = result.slice();
_result.push(multiset[i][j]);
combs(i + 1,multiset,k,_result);
}
combs(i + 1,multiset,k,result);
}
</pre><pre class="language-matlab">combs(0,[["1.A","8.A"],["2.B","5.B"],["3.C","7.C"],["4.D","6.D"]],4,[]);
</pre><p>You may use this website: https://repl.it/languages/javascript in order to run the Javascript code and see the result.</p><p>Now, I've tried to implement this recursive function in Matlab, but failed. Here is what I have tried:</p><pre class="language-matlab">function result = combs(index,multiset,k,temp)
</pre><pre class="language-matlab">result = temp;
</pre><pre class="language-matlab">% if length of result == k:
if (size(temp,1) == k)
</pre><pre> result = temp;
return;
end</pre><pre class="language-matlab">% if index > length of multiset:
% return
if ((size(multiset,1) + size(temp,1) - index+1) < k)
</pre><pre> result = temp;
return;</pre><pre class="language-matlab">else
% else:
% for j in multiset[index]:
% combs(index + 1,multiset,k,result with multiset[index][j] added)
</pre><pre> for j = 1:size(multiset,2)
temp = result;
temp(end+1,j) = multiset(index,j);
temp = combs(index + 1, multiset, k, temp);</pre><pre> end</pre><pre> temp = combs(index + 1, multiset, k, temp);
end
result = temp;
end</pre><p>If anybody has the knowledge to properly port this to Matlab, I would be very glad! :)</p>D LPhttp://de.mathworks.com/matlabcentral/profile/authors/6855008-d-lptag:de.mathworks.com,2005:Question/2385332015-09-01T07:49:08Z2015-09-01T20:19:54ZHow to create a GUI?<p>hello everyone, i need your help.
I have to create a GUI that reads data from excel. I need to:
-show those data into GUI window;
-edit those data from GUI window (not in excel), and save those modifications;
-plot some of columns into a graphic.</p>Daniele Morellohttp://de.mathworks.com/matlabcentral/profile/authors/6715608-daniele-morellotag:de.mathworks.com,2005:Question/2388202015-09-01T20:11:21Z2015-09-01T20:18:29ZAssigning an Array to Structure Field<p>I'm having trouble assigning an array to a structure field.</p><pre class="language-matlab">shuff = randperm(length(unshuff));
[unshuff.trial] = shuff;
</pre><p>I get the following error message:</p><pre class="language-matlab">Too many output arguments.
</pre><p>Any ideas?</p>Nick Ghttp://de.mathworks.com/matlabcentral/profile/authors/3714359-nick-gtag:de.mathworks.com,2005:Question/2386002015-09-01T10:31:24Z2015-09-01T20:09:47ZMatlab Electromyography (EMG) signal<p>Hi all,</p><p>Can anyone help me find an ENG signal sample?</p><p>I found the document in the link below where an emg.txt file is mentioned. Does anyone know from where I can find this file or how to replicate an EMG signal?</p><p><a href = "http://www.biomech.uottawa.ca/english/teaching/apa6905/lab/MatLab%2520Help%2520-%2520EMG%2520Analysis.pdf"><http://www.biomech.uottawa.ca/english/teaching/apa6905/lab/MatLab%20Help%20-%20EMG%20Analysis.pdf</a>></p>John Smithhttp://de.mathworks.com/matlabcentral/profile/authors/6481845-john-smithtag:de.mathworks.com,2005:Question/2388082015-09-01T18:48:13Z2015-09-01T20:05:07ZHow can I plot histogram using b as x value and k as bin values? plotting histogram error line 16<pre class="language-matlab">load sizes2.txt
results= sizes2(:,1)
n=size(sizes2,1) % num of rows
a=sizes2(:,:)
b=sort(a)
y=log10(n)
k= 1+3.322*y % is suggested number of class intervals and n is the number of values in the data set
</pre><pre class="language-matlab">fprintf('The suggested number of class intervals is %d\n', k );
</pre><pre class="language-matlab">x=range(b)
w=x/k % width of class intervals
fprintf('The suggested number of class intervals is %d\n', w)
k=8
hist(b,k)
</pre><p>Thank you</p>Jackiehttp://de.mathworks.com/matlabcentral/profile/authors/5856280-jackietag:de.mathworks.com,2005:Question/2388192015-09-01T20:03:06Z2015-09-01T20:03:06ZHow to use two columns from a spreadsheet in differential equation<p>I have a spreadsheet of data points taken at specific times. I would like to use the time points as tspan in my differential equations and use the data points as input into the dy(1). Essentially, I need to evaluate at each time point using the time paired data point as input into the first equation of my system. I've tried importing the data and times as two separate variables and then indicating tspan='TIME' which gave me the error message of "The entries in tspan must strictly increase or decrease" which they do all decrease. I haven't had any luck trying to figure out to input the paired data values into dy(1). Any advice would be appreciated!</p><p>RAB</p>RABhttp://de.mathworks.com/matlabcentral/profile/authors/5826399-rabtag:de.mathworks.com,2005:Question/2388182015-09-01T20:01:52Z2015-09-01T20:01:52ZCompiling a C/C++ function with external dependencies<p>There is a cross-platform library called LCM, the lightweight communication and marshaling protocol, which provides some cool interprocess communication capabilities. I have C functions that can publish and subscribe to LCM channels. I want to get these functions into a Simulink block so that I can communicate with a running model from other processes. These functions, of course, have a dependency on the LCM library. I can compile this program in my C IDE with a cmakelists file - what is the most straightforward way to compile this program for Matlab?</p>Ryanhttp://de.mathworks.com/matlabcentral/profile/authors/4349122-ryantag:de.mathworks.com,2005:Question/2388172015-09-01T20:00:06Z2015-09-01T20:00:06ZError from glmfit - any ideas??<p>Y is 1111 X 1
X is 1111 X 2
... <b>[b2,dev,st] = glmfit(Y,X,'normal');</b>
Error using <
Matrix dimensions must agree.</p><p>Error in glmfit (line 330)
t = (sqrtw < wtol);</p>Shell Lianghttp://de.mathworks.com/matlabcentral/profile/authors/6606580-shell-liangtag:de.mathworks.com,2005:Question/2375142015-08-28T21:26:17Z2015-09-01T19:44:04ZStill having problems loading libraries with 2015a and windows 10<p>Further to my previous question, I tried following the example in the loadlibrary() help menu:</p><pre class="language-matlab">>> matlabroot
</pre><pre class="language-matlab">ans =
</pre><pre class="language-matlab">C:\Program Files\MATLAB\R2015a
</pre><pre class="language-matlab">>> addpath(fullfile(matlabroot,'extern','examples','shrlib'))
>> loadlibrary('shrlibsample')
</pre><pre class="language-matlab">Index exceeds matrix dimensions.
</pre><pre class="language-matlab">Error in loadlibrary>getLoadlibraryCompilerConfiguration (line 527)
</pre><pre class="language-matlab">Error in loadlibrary (line 263)
</pre><p>Can someone please explain why I can't even load the dll example that is in the matlab help? Is this a windows 10 compatibility problem?</p>Tim G.http://de.mathworks.com/matlabcentral/profile/authors/759893-tim-gtag:de.mathworks.com,2005:Question/2386492015-09-01T12:02:12Z2015-09-01T19:42:17ZPortfolioCVaR object: how insert a non linear condition<p>Is it possible to insert a non linear condition in the PortfolioCVaR object? like in the fmincon function?
Thanks!</p>Cihanhttp://de.mathworks.com/matlabcentral/profile/authors/4060048-cihantag:de.mathworks.com,2005:Question/990672013-03-05T15:36:00Z2015-09-01T19:36:15ZWhy do I receive the error "License Manager Error -9"?<p>When I attempt to launch MATLAB, I receive the following error:</p><p> </p><pre class="error"> License checkout failed. Invalid host. License Manager Error -9</pre>MathWorks Support Teamhttp://de.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:de.mathworks.com,2005:Question/2388152015-09-01T19:33:03Z2015-09-01T19:35:54Zhow to generate random number at certain entries of a vector<p>I have a question about generate random number.For example I have a vector of side 10. If I want to use rand() function to generate instantaneously random numbers for only some elements in the vector, how can I do that. Specifically let say I have a defined vector and I only want to apply rand() function only to those entries whose value is smaller than 0.5, which can be found by using find() function.</p><p>%% x = rand(10,1);
%% ind = find(x<0.5);</p><p>THanks,
Vu</p>Vuhttp://de.mathworks.com/matlabcentral/profile/authors/5488787-vutag:de.mathworks.com,2005:Question/2384492015-08-31T21:50:17Z2015-09-01T19:34:19ZInstallation Error - Task MATLAB R2015a Startup Accelerator does not exist<p>I recently installed Windows 10 and have been unable to install MATLAB 2015a. I keep getting the following error:</p><img src = "/matlabcentral/answers/uploaded_files/36445/Untitled.jpg"><p>The log file shows:</p><pre class="language-matlab">(Aug 28, 2015 17:15:36) Task MATLAB R2015a Startup Accelerator for C:\Program Files\MATLAB\R2015a does not exist
(Aug 28, 2015 17:15:36) java.lang.NullPointerException
at com.mathworks.install.ComponentSizeAggregator.add(ComponentSizeAggregator.java:13)
at com.mathworks.install.ProductInstallerImpl.downloadProducts(ProductInstallerImpl.java:96)
at com.mathworks.install.ProductInstallerImpl.installProducts(ProductInstallerImpl.java:57)
at com.mathworks.install.InstallerImpl.install(InstallerImpl.java:100)
at com.mathworks.installwizard.model.InstallTask.execute(InstallTask.java:46)
at com.mathworks.installwizard.model.AbstractBackgroundTask.execute(AbstractBackgroundTask.java:38)
at com.mathworks.installwizard.model.AbstractTask.call(AbstractTask.java:73)
at com.mathworks.installwizard.model.AbstractTask.call(AbstractTask.java:23)
at com.mathworks.wizard.worker.WorkerImpl.doInBackground(WorkerImpl.java:24)
at javax.swing.SwingWorker$1.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at javax.swing.SwingWorker.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
</pre><p>I have attached a sample of my log file showing the complete error. One thing to note (and I suspect it may be part of the problem) is that I used sysprep <a href = "http://www.tenforums.com/tutorials/1964-users-folder-move-location-windows-10-a.html">as shown here</a> to relocate my Win10 user folder to a different partition. Can anyone comment on if this would produce this error or am I dealing with something else entirely?</p>Chrishttp://de.mathworks.com/matlabcentral/profile/authors/5910971-christag:de.mathworks.com,2005:Question/2385922015-09-01T09:49:18Z2015-09-01T19:32:58ZFormat Bar Graph Matlab<p>I use the following code to generate a bar plot:</p><pre class="language-matlab">% generate numbers to plot
a = rand(20,1);
b = rand(20,1)+1;
[i, ~]= size(a);
x = (1:i)';
</pre><pre class="language-matlab">M =4;
</pre><pre class="language-matlab">hold on
</pre><pre class="language-matlab">% generate bar plot for the high values
for k = 0: M
D(k+1,1) = bar((4*k+1 : 4*k+4),b(4*k+1 : 4*k+4),0.3);
set(D(k+1,1),'FaceColor',[0.1*k 0.25*k 1-0.25*k]);
end
% generate bar plot for the smaller values in front
for k = 0: M
E(k+1,1) = bar((4*k+1 : 4*k+4),a(4*k+1 : 4*k+4),0.5);
set(E(k+1,1),'FaceColor',[0.1*k 0.15*k 0.4-0.1*k]);
end
</pre><pre class="language-matlab">% style
xLabl ={'1', '5', '10' , '20', '1', '5', '10' , '20', '1', '5', '10' , '20', '1', '5', '10' , '20', '1', '5', '10' , '20'};
set(gca, 'XTick', x, 'XTickLabel', xLabl);
axis([0, inf, 0,inf]);
grid;
legend('T_p = 0.5', 'T_p = 1.0', 'T_p = 1.5', 'T_p = 2.0', 'T_p = 3.0', 'Location','northwest');
xlabel('N');
</pre><p>I plot the maximum and mean values of my test results for different combinations of the paramters N and T_p. Results with the same choice for T_p are plotted in the same color, as indicated in the legend. But the color varies slightly for the mean and max value. I was wondering if it is possible to extend the legend to display both corresponding bar colors to the choice of T_p. It should look something like this:</p><img src = "/matlabcentral/answers/uploaded_files/36454/untitled.png"><p>What I am looking for is to extent the legend. As I tried to show with my additions from paint. I want to use the colors of the bars in the background in the legend and specifically for the same values of T_P in the same row. Idealy I could distinguish these to coloumns of the legend with the coloum caption 'mean' and 'max'. Is this possible?</p>Felixhttp://de.mathworks.com/matlabcentral/profile/authors/3140726-felixtag:de.mathworks.com,2005:Question/2388122015-09-01T19:03:00Z2015-09-01T19:20:15ZIndex exceeds matrix dimensions<p>I keep getting an error every TIME i RAN THIS LOOP:
%loop</p><pre class="language-matlab">M(:,:,:,1)=M1;
M(:,:,:,2)=M2;
M(:,:,:,3)=M3;
YC(:,:,1)=YC1;
YC(:,:,2)=YC2;
YC(:,:,3)=YCC3;
</pre><pre> [M1]=ProbabiltyCounty1( X,Lam ,YC1)
[M2]=ProbabiltyCounty1( X,Lam ,YC2)
[M3]=ProbabiltyCounty1( X,Lam ,YCC3)</pre><pre class="language-matlab">for i= 1:3;
</pre><pre class="language-matlab">for j=1:3;
YC= YC(:,:,i);
MatrixM= M(:,:,:,j);
end
</pre><pre class="language-matlab">end
</pre><pre> FinalOutput= [MatrixM]</pre><pre> AYesIdiditNow2=[FinalOutput];</pre><pre class="language-matlab">Index exceeds matrix dimensions.
</pre>Amine Ben Ayara http://de.mathworks.com/matlabcentral/profile/authors/6651884-amine-ben-ayaratag:de.mathworks.com,2005:Question/2388112015-09-01T19:02:37Z2015-09-01T19:18:39ZWhy is MyCellArray{:} different than x = MyCellArray{:}?<p>I have a 32x1 cell array, each cell is a 600x1 matrix. I originally wanted to average the matrix elements across the 32 cells, the result being a 600x1 mean matrix. Purely by accident I discovered that</p><pre class="language-matlab">MyCellArray{:}
</pre><p>results in the desired mean matrix, while</p><pre class="language-matlab">x = MyCellArray{:}
</pre><p>results in the contents of the first array. I would like to know why they are different, and how can I automatically assign the ans from MyCellArray{:}?</p>Zacharyhttp://de.mathworks.com/matlabcentral/profile/authors/4115684-zacharytag:de.mathworks.com,2005:Question/2366612015-08-26T12:02:16Z2015-09-01T19:13:03ZPlot bilinear interpolated gridded data spatially on a map (Cannot get Interp2 to give smooth output)<p>I am using the following code to plot gridded data on a map over a region but I would like to know how to plot the interpolated data so that I get continuous data plotted over the region and the data does not look gridded. 'lat' and 'lon' are vectors (1x21 and 1x33) containing the latitude and longitude coordinates respectively.</p><pre class="language-matlab">ax = worldmap(latlim, lonlim);
S = shaperead('landareas','UseGeoCoords',true);
surfacem(lat, lon, ans');
geoshow([S.Lat], [S.Lon],'Color','black');
</pre><p>I am seeing a lot of documentation on using interp2 but I am not getting mine to work even when I try to create a meshgrid using lat and lon (cannot attach the data). I do the following with interp2:</p><pre class="language-matlab">LON,LAT] = meshgrid(unique(lon),unique(lat));
interp2(lon, lat, testdata', LON, LAT);
</pre><p>That gives me a result but I then want to plot it over a region without it looking gridded. testdata is a 33x21 matrix. Any ideas? I have seen some examples here on interpolation but I am not sure how to apply it conveniently with the data I have. I am surprised that there is not more information on this or why I am just sucking at finding the answer!</p><p>Thanks,</p>mashtinehttp://de.mathworks.com/matlabcentral/profile/authors/4739967-mashtinetag:de.mathworks.com,2005:Question/2388142015-09-01T19:11:16Z2015-09-01T19:11:16ZParallel training of SOM on GPU<p>train (trainbu) function for SOM network doesn't run on GPU because of negdist function is not in the GPU list. Is it possible to use GPU for parallel training of SOM?</p>Alexanderhttp://de.mathworks.com/matlabcentral/profile/authors/2349762-alexandertag:de.mathworks.com,2005:Question/2388132015-09-01T19:10:15Z2015-09-01T19:10:15ZHow do you take the double click off of impoly to make the program run smoother? <p>Right now I have a polygon region that covers a part of a bacterial cell and then it continues to a new set of coordinates and creates another polygon and so on until the coordinates at the end of the cell are used. These coordinates come from the Matlab program called MicroTracker. How can I automate this so I do not have to double click inside each of these polygons to make it go to the next? I want it do be able to do all the regions after just hitting run. If you would like to see the code I will post it. Just let me know.</p><p>Thanks
Bryant Walker</p>Bryanthttp://de.mathworks.com/matlabcentral/profile/authors/5954845-bryanttag:de.mathworks.com,2005:Question/2387382015-09-01T14:48:12Z2015-09-01T19:00:23ZHow to convert my matlab codes into a dot exe file which does not use matlab software?<p>I have a Matlab codes which I would want to convert to a standalone program which requires no Matlab to for installation and usage. How could this be done?</p>AbelM Kusemererwahttp://de.mathworks.com/matlabcentral/profile/authors/6629735-abelm-kusemererwatag:de.mathworks.com,2005:Question/2387922015-09-01T16:52:38Z2015-09-01T18:58:38Z How can i rearrange a vector ?<p>I need you help in matlab</p><p>if A=[8 1 12 3 6 10 13 3];</p><pre> AVG=sum(A)/length(A);</pre><pre> i need to neglect all values that below the AVG</pre><pre> so i get B=[8 12 10 13]</pre><p>can you help me to perform this task in general</p>Abdelwahab Fawzyhttp://de.mathworks.com/matlabcentral/profile/authors/6561729-abdelwahab-fawzytag:de.mathworks.com,2005:Question/2385112015-09-01T05:51:15Z2015-09-01T18:56:55Ziterative process for selecting optimum parameters in function<p>I have the following data:</p><pre class="language-matlab">d = ...
</pre><p><b>EDIT: Matt J moved data to attached .mat file</b></p><p>and I have the following function where the data is used:</p><pre class="language-matlab">function [mae, mod] = my_func(obs, x2, S, a, b, c, alpha)
</pre><pre> % start function
st = x2(1);
for i = 2:length(x2);
st(i) = alpha.*x2(i) + (1-alpha).*st(i-1);
end
st = st(:);</pre><pre> % main model equation
mod = a + b.*st + c.*S;</pre><pre> % calculate mean absolute error
mae = nanmean(abs(mod - obs));
end</pre><p>I can use the data in the function as:</p><pre> obs = d(:,1);
x2 = d(:,2);
S = d(:,3);</pre><pre> a = 0.5;
b = 0.5;
c = 0.5;
alpha = 0.5; % between 0 and 1
[mae, mod] = my_func(obs, x2, S, a, b, c, alpha);</pre><p>However, I don't know what the values for a, b, c, and alpha should be. The only thing that I know is that alpha should be between 0 and 1. So, I have been told to use an iterative process to find the best values for each of these parameters for reducing the mean absolute error of the model (which is calculated in the function).</p><p>I was thinking of doing this by using every possible combination of values (between some certain limits) in a loop but then though that this will take ages to run and probably isn't the best way forward. Is there a more sophisticated way that someone can suggest for doing this, keeping in mind that alpha has to be between 0 and 1.</p>Richard Woolwayhttp://de.mathworks.com/matlabcentral/profile/authors/6789137-richard-woolwaytag:de.mathworks.com,2005:Question/2387502015-09-01T15:31:36Z2015-09-01T18:55:29ZEasily working with numerical data in a cell array<p>I have a bunch of n x 2 matrices stored in a 1 x 37 cell array. The first column of each matrix is an x-position and the 2nd column is a y-position. How do I a) plot all the data as y vs. x; and b) how do I concatenate this into one long n x 2 matrix? My horrible workaround has been to use</p><pre class="language-matlab">celldisp
</pre><p>and then to copy and paste this into Excel!</p>Kirby Runyonhttp://de.mathworks.com/matlabcentral/profile/authors/4123125-kirby-runyontag:de.mathworks.com,2005:Question/2385612015-09-01T08:56:06Z2015-09-01T18:54:37ZHow to find the name of the file that is being edited?<p>Hi,
I would like to write a Matlab script that performs an operation on the file that is being eddited (file that is displayed now in the editor window).
To do so, I need to know the name of the file.
I was looking all over the places and didn't find the solution.
To be more specific, I looking for a solution like gcf()
The reason I'm looking for such a solution is that I would like to do some analysis and processing on the eddited file like: Publish (without the Matlab option), save to...
Thank you,
Alecs</p>Alecsander Eitanhttp://de.mathworks.com/matlabcentral/profile/authors/654715-alecsander-eitantag:de.mathworks.com,2005:Question/2387412015-09-01T14:58:13Z2015-09-01T18:54:02ZMATLAB Plots in Microsoft Office<p>I once had a little program a colleague wrote that analyzed some data, created plots, and then embedded them in a Word document where I could click on the curve in the plot and it would update all the other plots to be clicked on the same point in time and we could easily see the value of the data on the plot as there was a little tag of sorts on the plot reading out the value.</p><p>I has been a number of years and the original program has been lost to time and upgraded software packages, however, we would like to create something similar today. Does anyone know how to do this? I know it can be done because I have seen it done before. The key is that the plots were not static in Word, but we were able to interact with them.</p>Jameshttp://de.mathworks.com/matlabcentral/profile/authors/3540346-jamestag:de.mathworks.com,2005:Question/2388092015-09-01T18:50:47Z2015-09-01T18:53:33ZHow to get 2-variable function from a GUI textbox?<p>Hey
I need to input a 2 variable function like f(x,y) and give x and y lower and upper limit and use numerical methods on it. I did it for 1 variable function(find a GUI) but now there are problems with f(x) turnning into f(x,y) and fevel(fx,x) that cannot be (fx,x,y).
here is .m file and the problem area:</p><p>x1 = str2double(get(handles.editx1,'String'));</p><p>x2 = str2double(get(handles.editx2,'String'));</p><p>fx = vectorize(inline(get(handles.editfunc,'String')));</p><p>x = [x1:0.001:x2];</p><p>values = feval(fx,x);</p><p>maxi=max(values);</p><p>mini=(min(values));</p><p>if mini > 0</p><pre> mini = 0;</pre><p>end;</p><p>method = get(handles.pop_int,'Value');</p>Peter weberhttp://de.mathworks.com/matlabcentral/profile/authors/6854240-peter-webertag:de.mathworks.com,2005:Question/2388102015-09-01T18:53:06Z2015-09-01T19:51:48ZAbout ploting values in array and holding them<p>I have following code as function</p><pre class="language-matlab">function PlotSample(x)
figure(1);
sublot(3,1,1);
[a,b]=hist(x);
hold on;
a=100*(a./size(x,1));
end
</pre><p>Now if i have diffrent values of x like x1,x2 and x3 all having size 100*2 then how to plot 6 histograms in 1 plot?</p>rathod ujjval rameshbhaihttp://de.mathworks.com/matlabcentral/profile/authors/6506111-rathod-ujjval-rameshbhaitag:de.mathworks.com,2005:Question/2388072015-09-01T18:25:41Z2015-09-01T18:25:41ZHow to generate MATLAB MEX functions from Simulink models <p>How to generate MATLAB MEX functions from Simulink models. Also please let me know what tools are required for this.</p>Susheel Bhalabhadrahttp://de.mathworks.com/matlabcentral/profile/authors/3465658-susheel-bhalabhadratag:de.mathworks.com,2005:Question/2388062015-09-01T18:25:37Z2015-09-01T18:25:37ZCan any one help me in WSN Optimization <p>i need a source code for any routing protocol in WSN that implement any optimization algorithm</p>Abdelwahab Fawzyhttp://de.mathworks.com/matlabcentral/profile/authors/6561729-abdelwahab-fawzytag:de.mathworks.com,2005:Question/1018362011-08-10T17:27:00Z2015-09-01T18:25:03ZHow can I display Russian Cyrillic characters in a figure in MATLAB 7.7 (R2008b)?<p>I want to add a TITLE or a TEXT object in my figure to display a Russian Cyrillic text string. I am using Finnish locale settings on Windows:</p><p> </p><pre class="language-matlab">slCharacterEncoding
</pre><pre class="language-matlab">ans =
</pre><pre class="language-matlab">windows-1252
</pre><p>all I see is question marks or empty squares when executing these commands:</p><p> </p><pre class="language-matlab">textInRussian = 'Россия'
title(textInRussian)
</pre>MathWorks Support Teamhttp://de.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:de.mathworks.com,2005:Question/2386602015-09-01T12:40:28Z2015-09-01T18:20:17ZIs it possible to view a signal in "Display" block in real time durring simulation?<p>Or is there any other block, which is dedicated for that purpose.</p><p>Thanks</p>maticohttp://de.mathworks.com/matlabcentral/profile/authors/6691258-maticotag:de.mathworks.com,2005:Question/2387452015-09-01T15:12:50Z2015-09-01T18:16:57ZFixing Contour Plot/ Smooting Contour plot<p>Hi all,</p><p>I have data x = [-50:1:50], y = [-50:1:50] and corresponding z values for each (x,y) point. I am trying to use the data to create a contour of all data above a set z value (i.e. v = [val val]). The data set I have is perfectly symmetric about the y axis (i.e. z(x,y) = z(x,-y)) and yet when using contour(x,y,z,v) the contour plot is not symmetric. I have tried using surf on the data and using view to get a 2-d slice. This also shows these discrepancies. From reading some threads on surf it appears each pixel is surf is determined by the data in the upper left hand corner. I am assuming the problems I am having with contour stem from a similar underlying method used by the contour function. Has anyone else run into this problem or does anyone else have an idea as to how I might force contours to look the same on both sides of the y axis or a way to smooth the contours so the major differences go away? Any ideas are welcome.</p><p>Thanks in advance for the help.</p>Tommyhttp://de.mathworks.com/matlabcentral/profile/authors/3952171-tommytag:de.mathworks.com,2005:Question/2388052015-09-01T18:16:50Z2015-09-01T18:16:50ZTimeout error NI DAQ recording encoder Position or EdgeCount using clock<p>I wish to record timestamped data from a quadrature encoder using an NI DAQ USB-6341 but I receive the "timeout" error below. Thank you for your help.</p><pre class="language-matlab">>>[data, time] = s.startForeground()
Timeout expired before operation could complete.
</pre><p>This script works correctly (Analog channel only, third line commented-out):</p><pre class="language-matlab">s = daq.createSession('ni');
addAnalogInputChannel(s,'Dev1', 0, 'Voltage');
%addCounterInputChannel(s,'Dev1', 0, 'EdgeCount');
s.DurationInSeconds = 0.25;
[data, time] = s.startForeground();
plot(time, data);
</pre><p>This script gives the timeout error mentioned above (third line active):</p><pre class="language-matlab">s = daq.createSession('ni');
addAnalogInputChannel(s,'Dev1', 0, 'Voltage');
addCounterInputChannel(s,'Dev1', 0, 'EdgeCount');
s.DurationInSeconds = 0.25;
[data, time] = s.startForeground();
plot(time, data);
</pre><p>This script (analog and digital single scans) works correctly too:</p><pre class="language-matlab">s = daq.createSession('ni');
addAnalogInputChannel(s,'Dev1', 0, 'Voltage');
addCounterInputChannel(s, 'Dev1', 0, 'EdgeCount');
data = inputSingleScan(s)
</pre><p>I based those scripts on the examples which I cannot run fully (timeout error above) from:</p><p><a href = "http://www.mathworks.com/help/daq/examples/measure-angular-position-with-an-incremental-rotary-encoder.html">http://www.mathworks.com/help/daq/examples/measure-angular-position-with-an-incremental-rotary-encoder.html</a></p><p><a href = "http://www.mathworks.com/examples/daq/2575-count-pulses-on-a-digital-signal-using-ni-devices">http://www.mathworks.com/examples/daq/2575-count-pulses-on-a-digital-signal-using-ni-devices</a></p><p>Thank you,</p><p>Guillermo</p>Guillermo Diaz Lankenauhttp://de.mathworks.com/matlabcentral/profile/authors/5455667-guillermo-diaz-lankenautag:de.mathworks.com,2005:Question/2373662015-08-28T09:07:26Z2015-09-01T18:12:09ZMS Excel function TODAY() not updating when opened using MATLAB XLSREAD<p>I use the TODAY() function in an excel worksheet which is accessed using MATLAB (i.e. I don't read the worksheet directly). Now I have to open the excel file just to update the TODAY() function, and this method is a bottleneck in my workflow.</p><p>I know it's possible to set Excel to automatically update cells upon being opened under the calculation tab, but apparently this does not apply to MATLAB (or COM interfaces in general?). Can someone give me an idea of what can be done?</p><p>EDIT: I'm using MATLAB's built in 'xlsread' command</p>Chris Coutinhohttp://de.mathworks.com/matlabcentral/profile/authors/6132885-chris-coutinhotag:de.mathworks.com,2005:Question/2388042015-09-01T18:01:18Z2015-09-01T18:08:18ZError using copyfile from a changing directory<p>I am pulling a file to read in from an always changing directory. I would like to copy this file into a directory I have it for storage and further data analysis.</p><pre class="language-matlab">this_folder = pwd
[data, path] = uigetfile('*csv')
data2 = fullfile(path, data)
</pre><p>do some processing then when I am finished</p><pre class="language-matlab">f_all = fullfile(this_folder, 'data_plots\All_data_plots')
copyfile(data2,f_all)
</pre><p>I get the error:</p><pre class="language-matlab">Error using copyfile
Argument must contain a string
</pre><p>The problem is data, data2, f_all, path, and this_folder are all characters so I am not sure what it means by must contain a string.</p>Calabresehttp://de.mathworks.com/matlabcentral/profile/authors/6198613-calabresetag:de.mathworks.com,2005:Question/2386792015-09-01T13:35:11Z2015-09-01T18:03:54ZGetting help for a function from another function<p>Dear all,</p><p>suppose I want to get help from a function. I can simply type h=help('myfunction). But then suppose that I have another function, say myfunction2 which is identical to myfunction. As an example myfunction2 could be as follows</p><pre class="language-matlab">function [a,b,c]=myfunction2(varargin)
[a,b,c]=myfunction(varargin{:});
end
</pre><p>It is clear that myfunction and myfunction2 will have the same behavior. The question is, if I want to get help for myfunction2, is it possible to get it from myfunction?</p><p>Thanks</p>Patrick Mbomahttp://de.mathworks.com/matlabcentral/profile/authors/1075584-patrick-mbomatag:de.mathworks.com,2005:Question/2380962015-08-30T23:00:02Z2015-09-01T18:00:04ZPrint Simulink Model in one File (pdf Format)<p>How is the command to print a list of Simulink Model Subsystems in one single file?
Each subsystem shall one separate page.</p><p>Any ideas how to do?</p>Christian Schulteshttp://de.mathworks.com/matlabcentral/profile/authors/1649908-christian-schultestag:de.mathworks.com,2005:Question/2382762015-08-31T09:53:25Z2015-09-01T17:58:38ZHow to cast two uint8 into int16 in Simulink?<p>I have two uint8 as input of my system. Together, they represent an int16. How can I cast these two values into an int16? In MATLAB, I would convert them to uint16, shift the bits of the first one 8 to the left and the use bitwise OR to get the bit representation and finally apply a typecast to reinterpret the bits (with respect to two's complement). In MATLAB it works:</p><pre class="language-matlab">raw = uint8([255,255])
raw = uint16(raw)
myint16 = typecast(bitor(bitshift(raw(1),8), raw(2)), 'int16') %myint16 = -1
</pre><p>How do I implement this in Simulink? I am restricted to the slcilib (for Code Inspector Compliance). That's why I cannot use the typecast function. Finally, I found a solution, but it's a really complicated if-then-else stuff, with around four casts. Is there another easy way?</p>Markushttp://de.mathworks.com/matlabcentral/profile/authors/3151566-markustag:de.mathworks.com,2005:Question/2384372015-08-31T18:29:58Z2015-09-01T17:48:11ZHow to plot dirac n-th derivation ?<p>I dont know how to plot this function which contains first and second derivation of dirac.</p><p>This is how i tried to solve it</p><p>Y= 80.624*t + 731939*dirac(t) + 6.373*(t^2) + 4663650*dirac(t,1) + 159*dirac(t,2) + 124126*(t^3);</p><p>ezplot(Y ,[0 1])</p><p>But Matlab send me:</p><p>Error using sym/dirac</p><p>Too many input arguments</p><p>Can someone please help.
Thanks</p>joejonsonhttp://de.mathworks.com/matlabcentral/profile/authors/5979009-joejonsontag:de.mathworks.com,2005:Question/94792011-06-14T18:09:11Z2015-09-01T17:40:09ZC++0X in mex<p>I have a piece of code that I need to wrap in a mex file. The original code makes use of gnu++0x (or c++0x) standard by using "-std=gnu++0x" directive for g++. When I tried to add this directive to mex through</p><p>CFLAGS="\$CFLAGS -std=gnu++0x"</p><p>it does not recognize that I am requesting use of gnu++0x standard. However, if I use</p><p>CXXFLAGS="\$CXXFLAGS -std=gnu++0x"</p><p>then I get the following error</p><p>In file included from /home/agadre/Applications/matlab/R2010a/extern/include/mex.h:60,
from hybrid_astar.cpp:4:
/home/agadre/Applications/matlab/R2010a/extern/include/matrix.h:330: error: redeclaration of C++ built-in type ‘char16_t’</p><p>And of course if I comment out the piece of code that requires c++0x, then everything compiles just fine.</p><p>Is it even possible to compile mex files using c++0x? I would appreciate any inputs in this regard.</p><p>Thanks.</p>Adityahttp://de.mathworks.com/matlabcentral/profile/authors/1080669-adityatag:de.mathworks.com,2005:Question/2387992015-09-01T17:39:53Z2015-09-01T17:39:53ZHow do I access instructor options such as Create a Course and Copy problems?<p>I am using Cody for the first time for a large Freshman general engineering course. Overall everything seems to be working smoothly, but I now that I am starting to plan for next semester, I have found that I don't seem to have access to some of the options that are mentioned in the Cody Coursework instructions for instructors.</p><p>For instance, I don't seem to have the option to create a new course (or to copy an existing one):</p><img src = "/matlabcentral/answers/uploaded_files/36488/Dropdown.png"><p>Or to copy a problem:</p><img src = "/matlabcentral/answers/uploaded_files/36489/Copy.png"><p>Have there been updates to the system since the instructions were posted, or is there a problem with my account where I don't have full instructor privileges?</p>William Martinhttp://de.mathworks.com/matlabcentral/profile/authors/6775628-william-martintag:de.mathworks.com,2005:Question/792812013-06-17T11:41:58Z2015-09-01T17:30:34ZCreate a structure name based on the string of a variable. Create fieldnames in this structure.<p>Inside a function I have a variable called name which is a char class. I want to generate a structure based on the string of variable *name *and then create fields in this structure.</p><pre class="language-matlab">name =
</pre><pre class="language-matlab">report 1
</pre><p>I do the following to create a variable with the string of variable name.</p><pre class="language-matlab">v=genvarname(strrep(name, ' ', '_'));
</pre><p>Then in my function I have created other variables which have certain values. I want to create fieldnames in the previous structure with the name of these variables. Those fieldnames will have the same value as the corresponding value of the variable.</p><p>example:</p><pre class="language-matlab">a=mean([1 2 3 4]);
b=std([1 2 3 4]);
</pre><p>What I want to create is the following:</p><pre class="language-matlab">report_1.a= 2.5000
report_1.b=1.2910
</pre><p>My final goal is to create an output in the function with structure report_1.</p>Giorgos Papakonstantinouhttp://de.mathworks.com/matlabcentral/profile/authors/3060153-giorgos-papakonstantinoutag:de.mathworks.com,2005:Question/2380542015-08-30T16:03:36Z2015-09-01T17:19:39ZChanging parameters in an ODE<p>I wish to change one of the parameters at each time step for an ODE solution plot. My function is as follows:</p><pre> function [t,v]=shig(b,p,m,yo)
[t v] = ode45(@fnsirtry,[0 12],yo);</pre><pre> function fnsir = fnsirtry(t,v)
a = 0.25;
r = 0.14;
fnsir(1) = p - m*v(1)-b*v(1)*v(2)+a*v(3);
fnsir(2) = (b*v(1))- (m + r)*v(2);
fnsir(3) = (r*v(2))-((m+a)*v(3));
fnsir = fnsir(:);</pre><pre> end
end</pre><p>When I plot the ODE, I want to change the value of b at each step. I have used a code like teh following:</p><pre class="language-matlab">temp = [5 9 12 17 19 24 28 27 22 17 10 7];
beta = 0.0000025*temp;
i = [1 2 3 4 5 6 7 8 9 10 11 12];
for i = 1;
b = beta(:,1)
end
for i = 2;
b = beta(:,2)
end
for i = 3;
b = beta(:,3)
end
for i = 4;
b = beta(:,4)
end
for i = 5;
b = beta(:,5)
end
for i = 6;
b = beta(:,6)
end
for i = 7;
b = beta(:,7)
end
for i = 8;
b = beta(:,8)
end
for i = 9;
b = beta(:,9)
end
for i = 10;
b = beta(:,10)
end
for i = 11;
b = beta(:,11)
end
for i = 12;
b = beta(:,12)
end
</pre><pre class="language-matlab">P = 5000;
m = 0.013;
</pre><pre class="language-matlab">yo = [200000 160 0];
[t v] = shig(b,p,m,yo);
w = [159
148
143
137
102
91
85
137
119
108
104
100];
subplot (1,2,1)
plot(t,v(:,2))
%,'-r*','Linewidth',1.5,'MarkerSize',5)
title('Infected Population')
%legend('Disease free state','Test state')
subplot(1,2,2)
plot(w)
</pre><p>Could I please get some light on this,, pls...</p>Ojaswitahttp://de.mathworks.com/matlabcentral/profile/authors/4283965-ojaswitatag:de.mathworks.com,2005:Question/2387962015-09-01T17:15:17Z2015-09-01T17:15:17Zi work on registration job for two different images , the first is X-RAY (medical) image and the second is normal(RGB) image, to do that i must find the correspondences between them . i need firstly to convert the two images to identical form . Plea<p>i work on registration job for two different images , the first is X-RAY (medical) image and the second is normal(RGB) image, to do that i must find the correspondences between them .
i need firstly to convert the two images to identical form . Please suggest me suitable and effective answer.</p>ikhlas watanhttp://de.mathworks.com/matlabcentral/profile/authors/6248747-ikhlas-watantag:de.mathworks.com,2005:Question/2386762015-09-01T13:29:17Z2015-09-01T17:10:07Zi am trying to execute the problem code but i am getting error in this line "Linedata(n1+k,:)=Candidate(sw1(k),:);"<p>i am trying to execute this problem code but i am getting error in it.</p><pre class="language-matlab">function f=bench_func(x)
[ps,d]=size(x);
%Transmission Network Expansion Planning
% Maximum and minimum bound of the population that to be generated is 1 and 16.
sw=ceil(x);
data6Bus;
n1=length(Linedata(:,1));
sw1=sw;
for k=1:length(sw1)
Linedata(n1+k,:)=Candidate(sw1(k),:);
end
n_orginalLine=n1;
n=length(Pgen);
B=zeros(n,n);
Nline=length(Linedata(:,1));
%Ncand=max(Candidate(:,1));
Xline=Linedata(:,4);
pijmax=Linedata(:,6);
Tap=ones(n);
for C=1:Nline
bline(C)=1/Xline(C);
k=Linedata(C,2);
m=Linedata(C,3);
B(k,m)=B(k,m)-(bline(C));
B(m,k)=B(k,m);
B(k,k)=B(k,k)+(bline(C));
B(m,m)=B(m,m)+(bline(C));
end
B(1,1)=10000000;
X=inv(B);
delP= Pgen-Pload;
delP=(delP');
delta=X*(delP);
pij=zeros(Nline,1);
for k=1:Nline
i=Linedata(k,2);
j=Linedata(k,3);
pij(k)=(delta(i)-delta(j))/Xline(k);
end
PIPbase=0.0;
f=sum(Linedata(n_orginalLine+1:end,7))+30;
pen=0;
for i=1:length(Linedata(:,1))
pen=pen+5000*max((abs(pij(i))-Linedata(i,6)),0);
end
for i=1:length(Candidate(:,1))
[a ]=find(sw==i);
if length(a)>3
pen=pen+1000;
end
end
f=f+pen;
</pre><p>error</p><pre class="language-matlab">Attempted to access Candidate(-5,:); index must be a positive integer or logical.
Error in algorithm>bench_func (line 112)
Linedata(n1+k,:)=Candidate(sw1(k),:);
Error in algorithm (line 60)
Fnew=bench_func(S(i,:));
</pre><p>please help me to solve this error.</p>Muhammad Umerhttp://de.mathworks.com/matlabcentral/profile/authors/6564239-muhammad-umertag:de.mathworks.com,2005:Question/2387542015-09-01T16:00:32Z2015-09-01T17:07:17ZHow to keep only positive values in an array?<p>I have a sorted array with different values:
-18 -13 0 8 51 133 255</p><p>I only keep the positive values :
0 8 51 133 255</p><p>How do i do this?</p>Priyanka Royhttp://de.mathworks.com/matlabcentral/profile/authors/5567803-priyanka-roytag:de.mathworks.com,2005:Question/2384322015-08-31T17:30:15Z2015-09-01T16:57:51ZFor my GUI, how can I have one button open the file then the other buttons modify that file?<p>How would I link the file I open to the other buttons?</p>shannon stoffelhttp://de.mathworks.com/matlabcentral/profile/authors/6822172-shannon-stoffeltag:de.mathworks.com,2005:Question/2387932015-09-01T16:56:38Z2015-09-01T16:56:38Zhow to extract a watermark in matlab?<p>the matlab code which i have used is:-</p><p>clear all; close all; clc;</p><p>bit=input('Please define which bit you want to extract from? (8 | 7 | 6 | 5)'); image=imread('C:\Users\user\Desktop\wm pictures\lena.jpg');</p><p>imshow(image);</p><p>[row,col]=size(image);</p><p>Hlength=row*col;</p><p>i=1;</p><p>j=1;</p><p>k=1; row=128;</p><p>col=384;</p><p>wmimage=imread('C:\Users\user\Desktop\wm pictures\cameraman.jpg');</p><p>wm=dec2bin(wmimage);</p><p>Wlength=row*col*8;</p><p>host=dec2bin(image);</p><p>cnt=0;</p><p>while i <= Hlength</p><pre> cnt=cnt+1;</pre><pre> if cnt>Wlength</pre><pre> break;</pre><pre> end
wm(j,k)=host(i,bit);
k=k+1;
if k>8
k=1;
j=j+1;
end
i=i+1;
end</pre><p>wm1=bin2dec(wm);</p><p>wm2=reshape(wm1,row,col);</p><p>wmimage(1:row,1:col)=wm2(1:row,1:col);</p><p>imwrite(wmimage,'extracted.jpg');</p><p>imshow(wmimage);</p><p>This code is not giving the desired result.
If anyone can give me some other codes for extraction in spatial domain then please help me out.
thank you</p>richa sharmahttp://de.mathworks.com/matlabcentral/profile/authors/6065264-richa-sharmatag:de.mathworks.com,2005:Question/2359522015-08-24T18:54:22Z2015-09-01T16:52:41Zthree figures in one figure for display<pre class="language-matlab">clf
figure(1);
colormap(jet)
pcolor(Uyear)
shading interp % remove the grid lines
colorbar
</pre><pre class="language-matlab">figure(2);
colormap(jet)
pcolor(Vyear)
shading interp % remove the grid lines
colorbar
</pre><pre class="language-matlab">figure(3);
colormap(jet)
pcolor(U2/V2)
shading interp
colorbar
</pre>sophiahttp://de.mathworks.com/matlabcentral/profile/authors/5688027-sophiatag:de.mathworks.com,2005:Question/2230062015-06-08T17:00:57Z2015-09-01T16:49:04ZSimulink Library Browser doesn´t show any blocks<p>Hello everybody,</p><p>I just installed Matlab 2015a (academic license) and found the simulink library browser empty, besides the recently used blocks entry (which is empty).
System is a Win7 Proffesional 64bit.</p><p>What can I do about it?</p>Stephan Hehttp://de.mathworks.com/matlabcentral/profile/authors/4566813-stephan-he