http://nl.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-11-22T00:29:52Ztag:nl.mathworks.com,2005:Question/1637252014-11-21T13:31:51Z2014-11-22T00:24:42ZCreating a large set of random numbers<p>Hello! I have the following problem. I need to generate 55 705 600 000 unique random numbers uniformly distributed from 0 to 1 (quite a lot, huh?). Usually I have a certain loop and I generate a random number on every iteration. However, that is obviously slow which is why I switched to generating all the random numbers I will need at the start of the program and putting them in a vector element.
The problem is that with this huge number (once again, 55 705 600 000) I cannot put them all in one vector because I get an "Out of Memory" message. That leaves me with the only option of generating one random number per iteration of a loop which (combined with the other parts of my code) will take me about half an year to complete!!! Do you have any alternative ideas about how I can speed up the process?
Thank you in advance!</p><p>Best regards</p>Martin/matlabcentral/answers/contributors/5754509-martintag:nl.mathworks.com,2005:Question/1637582014-11-21T18:32:12Z2014-11-22T00:24:39ZHow to draw same size rectangle on different image location<p>Hi,</p><p>I have selected random points using the below code</p><pre class="language-matlab">m = imread('a.jpg');
figure, imshow(m);
random_num = 50;
l = randi(numel(m), 1, random_num);
m(l) = 255;
figure, imshow(m);
</pre><p>Now I want to draw circle/rectangle for each random points. circle/rectangle for all points will be of equal size.</p><p>Can anyone assist me how to do that please.</p><p>Added an image for your information.</p><img src = "/matlabcentral/answers/uploaded_files/21483/random%20circle.jpg">Tania/matlabcentral/answers/contributors/5892299-taniatag:nl.mathworks.com,2005:Question/1634892014-11-20T02:46:03Z2014-11-22T00:17:32ZHow to use 'dates' and 'axis tight' for charts my data are in quarters in Matlab<p>Hi there
I have a code written to plot charts in quarters in matlab but need help on that. thanks. I attach the code and the data (127 observations) 1975q3-2007q3</p>Victor/matlabcentral/answers/contributors/4384288-victortag:nl.mathworks.com,2005:Question/1637872014-11-22T00:12:19Z2014-11-22T00:12:19ZHow can we adapt ANFIS to suit to a classification problem where the inputs are fuzzy variables and the output is a categorical variable such as class A,B or C<p>How can we adapt ANFIS to suit to a classification problem where the inputs have fuzzy partitions and the output is a class such as Class A,B,or C.</p>Mechanical Engineering/matlabcentral/answers/contributors/5909596-mechanical-engineeringtag:nl.mathworks.com,2005:Question/1637862014-11-21T23:21:50Z2014-11-22T00:07:40Zvariance equation of a white noise <p>Hi everyone,</p><p>I hope someone can answer this difficult question for me:</p><p>I am trying to implement a STFT transform algorithm on a noisy speech. I read a white noise wave and after preforming the STFT, I called D. Now, I need to solve this equation in matlab:</p><p>λd(k) = E{|Dk|^2}</p><p>I searched the net and found that this E is the variance function in matlab. But how do I calculate this function? Do I just take average of my D matrix and then square it and then subtract the kth element from it? or do I take the average and subtract the kth element squared?</p><p>Please help!!!</p>Mona/matlabcentral/answers/contributors/5899118-monatag:nl.mathworks.com,2005:Question/1637782014-11-21T21:32:49Z2014-11-22T00:00:36ZPlotting contour line and filling contours for coastline Island data?<p>My aim is to plot contour lines and fill these contour lines in using the function contourf. In order to show the area of the Island which would theoretically be safe to live on/ would be above sea level if the sea level were to rise.</p><p>I have tried numerous ways to attempt the above task but with great difficulty and have not succeeded. At present I have been able to plot a gray shaded relief map of the Island but cannot seem to get the coastline data not filled contours onto the map.</p><p>Assistance would be greatly appreciated.</p><p>The coastline data, and a picture of the ideal similar map that I want matlab to produce are also attached.</p><p>The attached map example if for temperature wheres as my plot will be for topographic elevation in relation to sea level rise for a different Island.
Thanks</p>Natasha/matlabcentral/answers/contributors/5875605-natashatag:nl.mathworks.com,2005:Question/1637762014-11-21T21:20:13Z2014-11-21T23:56:11Zsave scope plot in pdf format<p>If I have a matlab plot i use this command to save it in pdf format</p><p>print(figure(1), '-append', '-dpsc2', 'd:\fig.ps');</p><p>But if i have a plot from scope in simulink , how can i save it in pdf format?</p><p>Thanks
Matt</p>Matt/matlabcentral/answers/contributors/4010927-matttag:nl.mathworks.com,2005:Question/1636772014-11-21T05:03:53Z2014-11-21T23:47:08ZHow to read and store greyscaleimage into single matrix?<p>i have 2429 images in pgm format. each is in 19*19 size. Now i need to read all the images one by one and store in single matrix. With the help of previous mathworks available examples i read my file. now how to store in single matrix.</p><pre class="language-matlab">myFolder = 'C:\Users\smanohar\Documents\MATLAB\RBMimplementation\Gaussian RBM\gdrbm\greyscsalegdrbm\face';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.pgm');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
end
</pre>subha/matlabcentral/answers/contributors/4575737-subhatag:nl.mathworks.com,2005:Question/1637682014-11-21T20:14:30Z2014-11-21T23:39:26ZWrite a function dayName that has one input argument, day, containing the numerical value of a day in the month of November, 2014.<p>I was wondering if there was a shorter code to solve this problem? The solution I got was:</p><pre class="language-matlab">clc,clear
dayName = input('Enter date of month '); %input the date desired.
if dayName==1; %All following takes the date entered and returns the name of the day.
disp('Saturday')
elseif dayName==2;
disp('Sunday')
elseif dayName==3;
disp('Monday')
elseif dayName==4;
disp('Tuesday')
elseif dayName==5;
disp('Wednesday')
elseif dayName==6;
disp('Thursday')
elseif dayName==7;
disp('Friday')
elseif dayName==8;
disp('Saturday')
elseif dayName==9;
disp('Sunday')
elseif dayName==10;
disp('Monday')
elseif dayName==11;
disp('Tuesday')
elseif dayName==12;
disp('Wednesday')
elseif dayName==13;
disp('Thursday')
elseif dayName==14;
disp('Friday')
elseif dayName==15;
disp('Saturday')
elseif dayName==16;
disp('Sunday')
elseif dayName==17;
disp('Monday')
elseif dayName==18;
disp('Tuesday')
elseif dayName==19;
disp('Wednesday')
elseif dayName==20;
disp('Thursday')
elseif dayName==21;
disp('Friday')
elseif dayName==22;
disp('Saturday')
elseif dayName==23;
disp('Sunday')
elseif dayName==24;
disp('Monday')
elseif dayName==25;
disp('Tuesday')
elseif dayName==26;
disp('Wednesday')
elseif dayName==27;
disp('Thursday')
elseif dayName==28;
disp('Friday')
elseif dayName==29;
disp('Saturday')
elseif dayName==30;
disp('Sunday')
end %Ends function.
</pre>Jarred/matlabcentral/answers/contributors/5921894-jarredtag:nl.mathworks.com,2005:Question/1637832014-11-21T23:00:09Z2014-11-21T23:29:12Zi wrote this GUI file but still it's not connecting with the m file <ul><li>* % --- Executes on button press in BSI_Function.</li></ul><ul><li>function BSI_Function_Callback(hObject, eventdata, handles)</li><li>P_h = str2double(get(handles.P_h, 'String'));</li><li>T_s = str2double(get(handles.T_s, 'String'));</li><li>T_w= str2double(get(handles.T_w, 'String'));</li><li>S_d= str2double(get(handles.S_d, 'String'));</li><li>A_w_l= str2double(get(handles.A_w_l, 'String'));</li><li>N_s= str2double(get(handles.N_s, 'String'));</li><li>I_l=str2double(get(handles.I_l, 'String'));</li><li>P_l=str2double(get(handles.P_l, 'String'));</li><li>C_l= str2double(get(handles.C_l, 'String'));</li><li>S_w_s= str2double(get(handles.S_w_s, 'String'));</li><li>C_l_t=str2double(get(handles.C_l_t, 'String'));</li><li>C_t_c=str2double(get(handles.C_t_c, 'String'));</li><li>S= str2double(get(handles.S, 'String'));</li><li>T_o_s=str2double(get(handles.T_o_s, 'String'));</li><li>St_g=str2double(get(handles.St_g, 'String'));</li><li>M_e=str2double(get(handles.M_e, 'String'));</li><li>F_cu=str2double(get(handles.F_cu, 'String'));</li><li>D=str2double(get(handles.D, 'String'));</li><li></li><li>%BSI_Function(50,130,300,19,100,2,5,1,.5,2,.5,3,9,130,275,205,40,1800)</li><li>BSI_Function(P_h,T_s,T_w,S_d,A_w_l,N_s,I_l,P_l,C_l,S_w_s,C_l_t,C_t_c,S,T_o_s,St_g,M_e,F_cu,D)</li></ul><p>and on my main m.file before doing any calculations or entering the loop i used this code
function []=BSI_Function(P_h,T_s,T_w,S_d,A_w_l,N_s,I_l,P_l,C_l,S_w_s,C_l_t,C_t_c,S,T_o_s,St_g,M_e,F_cu,D)</p><p>i really need to do this right for my graduation project, i'm done with everything with the coding except this GUI
please help ..</p>abdulla ishaq/matlabcentral/answers/contributors/5848136-abdulla-ishaqtag:nl.mathworks.com,2005:Question/1637412014-11-21T16:11:15Z2014-11-21T23:21:12ZIntegrate a function multiple times; <p>1) I'm given: f(x) = x^2 - 3x - 5</p><p>I'm asked: "in which of the infinite integrals of f(x) does it take the value of 5 with x = 3?"</p><p>I thought of doing maybe a cycle with conditions inside until it finds the answer but I couldn't find a way to do it. Is there maybe a function that allows me to obtain for example the tenth integral of f(x) ? Something like int('x^2 - 3*x - 5',H) where H stands for 10 meaning it will return the function integrated 10 times.</p><p>2)Given g(x) = x^2 + 3x , find the integral in which its graphical representation passes through the point p(1,3)</p><p>I'm guessing this one is similar to 1), I'll have to do a cycle with conditions. Although the part that says that passes through p(1,3) don't really know how to verify it.</p><p>I'd appreciate very much any help.</p>Ramses Estay/matlabcentral/answers/contributors/5920127-ramses-estaytag:nl.mathworks.com,2005:Question/1637842014-11-21T23:06:41Z2014-11-21T23:17:24ZCan MATLAB be used in Arduino Applications?<p>I am currently taking Computational Methods (basically an Introduction to MATLAB) course at my university. I also recently purchased an Arduino microcontroller as I am switching majors (into Electrical Engineering) and wanted to get my hands dirty with some projects over winter break. Since I now have some experience and a good knowledge base of programming in MATLAB, I was hoping to use MATLAB to program the Arduino. I know that C or C++ is commonly used when programming the Arduino, but does it have the capability to run using MATLAB code? Thanks for your help.</p>Erik Dekelbaum/matlabcentral/answers/contributors/5580003-erik-dekelbaumtag:nl.mathworks.com,2005:Question/1579502014-10-09T04:05:26Z2014-11-21T23:00:36ZCan not run 'fitgmdist' function<p>I get an error saying "Undefined function 'fitgmdist' for input arguments of type 'struct'."</p>Isuri/matlabcentral/answers/contributors/2820257-isuritag:nl.mathworks.com,2005:Question/1615412014-11-06T07:57:10Z2014-11-21T22:53:00ZRack and pinion on moving base SimMechanics 1st generation<p>Hi,</p><p>I'm working on full vehicle simulations and on steering systems in particular. For my application I want to use a rack-and pinion to model the steering system. In my case the pinion is the steering-wheel input (axis which is fixed by a revolute joint to the chassis), the rack is the steering-rack which is connected to the tie rod and can translate wrt the chassis (prismatic joint). The whole chassis is of course not fixed in space but is driving around as well.</p><p>I've started of with the demonstration file mech_rack_pinion as provided by MATLAB. This file makes use of a velocity driver to link the translational velocity of the rack to the rotational velocity of the pinion.</p><p>I've altered this example slightly to correspond with the following drawing:</p><img src = "/matlabcentral/answers/uploaded_files/20602/Moving_rack_pinion.png"><p>As you can see the pinion should rotate according to the relative velocity of the rack w.r.t. the chassis. However in my model it rotates according to the global velocity of the rack. I can't seem to change this in the velocity driver block since the options there are very limited.</p><p>I've tried to change the orientation of the coordinate systems from world to base and follower but this doesn't help since the orientation of the axis is not the problem..</p><p>I've attached my file to show you the problem. I need this to work in SimMechanics 1st generation since my whole car-model is build in this as well.</p><p>Jan</p>Jan/matlabcentral/answers/contributors/1677928-jantag:nl.mathworks.com,2005:Question/1637472014-11-21T16:54:32Z2014-11-21T22:50:41ZHelp understand the sumsqr algorithm<p>For a current project, I've begun switching between versions of matlab.
For my trial of 2014, I guess I didn't download the neural network toolbox, so I can't use sumsqr.
When I used it on my other version I got what might be called an "impossible" answer.</p><p>In the study of wavelet compression techniques, one expects the original picture and the wavelet transform image to have the same energy.
Energy is defined as the sum of squared elements of thee matrix.
When I computed sumsqr on my MATLAB 2008, I got two different answers.</p><p>In order to try and understand the problem, I have 2 requests for the user community
1. Help me understand sumsqr. Does it square entries first, or sum the matrix first?
2 Is there code for qhat I want to do? That is, square the elements first, then sum them.</p>Brian/matlabcentral/answers/contributors/5771796-briantag:nl.mathworks.com,2005:Question/1637822014-11-21T22:29:07Z2014-11-21T22:49:21Zwhen i save .m files i get warning? why?<p>i am getting this warning</p><p>"The system cannot find the path specified "</p><p>i couldnot save my file further with this warning .But my program is in proper path. What will be reason</p>subha/matlabcentral/answers/contributors/4575737-subhatag:nl.mathworks.com,2005:Question/1636572014-11-21T01:24:21Z2014-11-21T22:38:40ZMatlab 2014b: graphics object deletion<p>I am comparing the behavior of the test code below in both R2013b and R2014b. In R2013b, running test.m results in the message 'User Data Present' being printed to the screen. However, when I run the very same code in R2014b, the message 'No User Data' is printed. Can anyone reproduce this and explain why the results are different?</p><pre> function test</pre><pre> imagesc(ones(100));</pre><pre> options = {'The Text','HorizontalAlignment', 'center',...
'color' , 'yellow','HitTest','off',...
'DeleteFcn',@MyDelete};</pre><pre> text(50,50,options{:});</pre><pre> set(gca,'UserData','User Data Present');</pre><pre> close(gcf)</pre><pre> function MyDelete(~,~)</pre><pre> d=get(gca,'UserData');</pre><pre> if isempty(d)
disp('No User Data')
else
disp(d)
end</pre>Matt J/matlabcentral/answers/contributors/1440443-matt-jtag:nl.mathworks.com,2005:Question/1637812014-11-21T22:08:46Z2014-11-22T00:29:52ZHow many years do i need to get the amount?<p>Imagine that you went to the bank and deposited $20,000 in an account that earns 6%
interest every year, with each year’s interest being deposited back into the account. Write
a MATLAB program that computes the number of years it would take to accumulate
$500,000.</p><p>the only thing i know is that 6% = 0.06 and i need to use a for loon with an if statement to solve this problem, i couldn't even start the program</p>Hamzah/matlabcentral/answers/contributors/5820933-hamzahtag:nl.mathworks.com,2005:Question/1631092014-11-17T20:47:48Z2014-11-21T22:11:20ZPrinting simulink file including all the blocks <p>Hi</p><p>I am using the following comand to save my simulink in pdf format</p><p>print -deps -r300 -sopen_loop myfig.ps</p><p>when see my file some part of my simulink blocks are cut down. Is there any syntax to fix this?</p><p>Thanks
Matt</p>Matt/matlabcentral/answers/contributors/4010927-matttag:nl.mathworks.com,2005:Question/1467442014-08-07T19:50:05Z2014-11-21T22:07:57ZJava to Matlab and back to Java<p>I am trying to compile and make available Matlab functions via a jar to be used in a Java application. I thought, given the support for Java collections in Matlab - meaning I can, say, create and use a java.util.HashMap in the matlab code - perhaps, I can pass it back to the calling Java method.</p><p>This part seems to work just fine. Meaning, I can make the round trip to matlab and back. However, the returned value from the matlab call is a MWJavaObjectRef, which I am not able to cast into a HashMap within the calling routine. I get the following error:</p><p>INFO 2014-08-06 15:26:08,408 [main] Server - Result type: com.mathworks.toolbox.javabuilder.MWJavaObjectRef
Exception in thread "main" java.lang.ClassCastException: com.mathworks.toolbox.javabuilder.MWJavaObjectRef cannot be cast to java.util.HashMap
at main.Server.initializeMatlab(Server.java:55)
at main.Server.main(Server.java:34)</p><p>The question then is:</p><p>1. Can you pass such java collections (created in matlab) back to Java?
2. It seems elegant, if it works. But, is this the prescribed way to do it?</p><p>My returned HashMap has values, which are themselves java.util.ArrayList and java.util.HashMap objects.</p><p>Any experiences, examples etc. would be greatly appreciated.</p><p>Here is my Java code:</p><pre class="language-matlab">// Test the matlab call
calcEngine = new CalculationEngine();
Object [] args = new Object[0];
Object[] result = calcEngine.CalcEngineTester(1,args);
log.info("Result type: " + result[0].getClass().getCanonicalName());
Object tempObj = (Object) result[0];
Map<String,Object> outputMap = (HashMap<String,Object>) tempObj; <<< This is what fails!
</pre><pre> // Matlab code
...
...
output1 = java.util.ArrayList();
output2 = java.util.HashMap();
outputMap = java.util.HashMap();
outputMap.put('A', output1);
outputMap.put('B', output2);</pre>Partha/matlabcentral/answers/contributors/2472417-parthatag:nl.mathworks.com,2005:Question/1637802014-11-21T21:50:27Z2014-11-21T21:50:27ZJava Crashing when initializing MCR object<p>I have a MATLAB program developed in 2014a that I packaged using the JA Builder. I have this program working wonderfully with Java in a test program. I then tried to integrate the MATLAB program into a much larger program that requires all files to be OSGi compliant. I made an OSGi bundle that appears to meet the standards however I am still having issues.</p><p>When the Java program gets to the point where it instantiates my MATLAB object, it just closes the program without any error messages. Any ideas?
ex:
MatlabProgram mp = new MatlabProgram();</p>Jake/matlabcentral/answers/contributors/5661406-jaketag:nl.mathworks.com,2005:Question/1637772014-11-21T21:26:20Z2014-11-21T21:49:22ZHow to save simulink blocks in pdf format<p>I am trying to save my simulink in pdf formate instead of sniping it. I am using the command below:</p><p>print -deps -r300 -smysimulink d:/mysimulink.ps</p><p>when i open my pdf it didnt capture the whole simulink blocks. Can anyone suggest a good method to save simulink blocks in pdf file.</p><p>Thanks</p><pre> Matt</pre>Matt/matlabcentral/answers/contributors/4010927-matttag:nl.mathworks.com,2005:Question/1637792014-11-21T21:45:17Z2014-11-21T21:45:17Zwhy i have this error when i try to start my connection with raspberry pi?<p>Hello guys, i have installed the Raspberry pi package support for matlab but when i give the command:</p><pre> mypi = raspi</pre><p>i obtain this error:</p><pre class="language-matlab">Error using raspi (line 160)
Cannot establish an SSH connection to the board with device address "192.168.1.2".
</pre><pre class="language-matlab">Caused by:
Error using raspi (line 156)
Error executing command: FATAL ERROR: Network error: Connection refused
</pre><p>During the installation of the package i have set a static ip for the raspberry in this way:</p><pre class="language-matlab">IPv4 Address. . . . . . . . . . . : 192.168.1.2
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
</pre><p>And, if is important for the resolution of my problem, i have connected the raspberry pi to my pc with a ethernet cable, and the pc is connects to internet with a usb key wireless. The router is not phisically connected to the pc.</p>squall141/matlabcentral/answers/contributors/5623433-squall141tag:nl.mathworks.com,2005:Question/1634492014-11-19T19:49:31Z2014-11-21T21:44:43ZGUIDE question regarding axes<p>Hello, thanks for looking at this,</p><p>I'm having trouble keeping track of the current axes in my GUIDE application. What I have is a simple GUIDE application with four axes: when I press on any of the four axes I can use the get(gca) command to find what axes I'm on. My problem comes when I plot anything: whenever I plot anything the gca is never set to whatever I click on anymore. I think it has something to do with clicking on the plot compared to clicking on the axes, hence the current axes handle never changes.</p><p>What is strange is if I use the command: get(figure1, 'CurrentAxes') I CAN find the axes I clicked on, but the get(gca) command opens a new figure with a new axes. I have a scroll function callback that uses command:</p><pre> if get(volprototype, 'CurrentAxes') == handles.axes1</pre><p>and I can use this to check if the axes does in face correspond to the current axes. My problem is when I execute this code, and do the scroll callback, it exits out if I scroll too quickly. I can scroll slowly and it works perfectly, but if I scroll quickly it creates a error.</p><p>So, here are my questions:</p><p>Why does it exit out if I scroll too quickly? Is there a better way I can check the current axes? This is causing a few problems for me, and I want to get this scroll function callback working before I continue with the rest of my application.</p>Brian/matlabcentral/answers/contributors/3177729-briantag:nl.mathworks.com,2005:Question/1637732014-11-21T20:58:17Z2014-11-21T21:42:46ZWrite a script that will convert each numeric value in the vector days into a string named daysOfWeek with the day names separated by a comma and a space.<p>So far I have:</p><pre class="language-matlab">clc,clear
day=input('Enter date of the month ');
if any(day==[3 10 17 24])
dayName = 'Monday' ;
elseif any(day==[4 11 18 25])
dayName = 'Tuesday' ;
elseif any(day==[5 12 19 26])
dayName = 'Wednesday' ;
elseif any(day==[6 13 20 27])
dayName = 'Thursday' ;
elseif any(day==[7 14 21 28])
dayName = 'Friday' ;
elseif any(day==[1 8 15 22 29])
dayName = 'Saturday';
elseif any(day==[2 9 16 23 30])
dayName = 'Sunday';
end
disp(dayName)
</pre><p>However, I am unable to get multiple values to work at once. Any help would be greatly appreciated!</p>Jarred/matlabcentral/answers/contributors/5921894-jarredtag:nl.mathworks.com,2005:Question/1637432014-11-21T16:31:23Z2014-11-21T21:39:13ZProblem with average two cells array <p>Dear expert,</p><p>I have this kind of problem: I have one cell array with 4420 cells, and in every cell there are 90 double values (in every cell I have one time series with 90 points). I need to keep the cells from 1 to 85 (every cell represent a brain's region) and make an average with the cells from 2211 to 2295 (the same 85 regions of the same brain, but it is different run, so different values). In other words I need to make an average between two time series of the same brain's region but from two different runs. After that I need to keep cells from 86 to 170 and make a average with cells from 2296 2380, and so on, until I will finish the 4420 array cell (I have 26 different brain for run1 and the same 26 brain for run2 ---> 26x85x2=4420).
I post below the code that generate this cell array (AllResult).</p><pre> %% Root Path
pathroot = 'C:\Temporal_series';</pre><pre> %% first level folder
MyExamDir = [30852 22061 20769 21734 21735 21977 20856 21976 20086 30697 30630 19993 30018 28832 19725 22440 28333 22439 22587 22586 21403 30944 21405 30943 22337 30948];</pre><pre> % convert it to string : easier to treat as folder Names.
MyStringDir = cellfun(@num2str,num2cell(MyExamDir),'UniformOutput',false);</pre><pre> % Initialize The Output Data (which will contain all the results
% Here, I assume all the files containts a 90x1 vector, so i will concatenate to create an array.
AllResult = [];</pre><pre> %% loop on every Exam folder
for i = 1:length(MyExamDir)</pre><pre> %% get all ".gz.txt" in the run1 folder
CurrentDir = fullfile(pathroot,MyStringDir{i},'run1');
AllFile = dir(fullfile(CurrentDir,'*gz.txt'));</pre><pre> % loop for each file
for j = 1:size(AllFile,1)</pre><pre> % current file
CurrentFile = fullfile(CurrentDir,AllFile(j).name);</pre><pre> % try to open
[fid, errormsg] = fopen(CurrentFile, 'r+');
if ~isempty(errormsg)
warning('failed to open %s due to %s', CurrentFile, errormsg);
else
A1 = fscanf(fid,'%f %f', [90 1]);
A1 = A1';
AllResult{end+1,1} = A1;
fclose(fid);
end
end</pre><pre> %% same operation for run2
CurrentDir = fullfile(pathroot,MyStringDir{i},'run2');
AllFile = dir(fullfile(CurrentDir,'*gz.txt'));</pre><pre> % loop for each file
for j = 1:size(AllFile,1)</pre><pre> % current file
CurrentFile = fullfile(CurrentDir,AllFile(j).name);</pre><pre> % try to open
[fid, errormsg] = fopen(CurrentFile, 'r+');
if ~isempty(errormsg)
warning('failed to open %s due to %s', CurrentFile, errormsg);
else
A1 = fscanf(fid,'%f %f', [90 1]);
A1 = A1';
AllResult{end+1,1} = A1;
fclose(fid);
end
end
end</pre><p>Could someone help me?
Thanks in advance for your attention.</p><p>Lorenzo</p>Lorenzo/matlabcentral/answers/contributors/5880518-lorenzotag:nl.mathworks.com,2005:Question/553562012-12-01T13:06:56Z2014-11-21T21:34:05ZHow to reverse a number<p>Hi,
I want to reverse a number, not a vector, like 8549 to 9458.
I used fliplr , or flipud, or y = x(end:-1:1), They just work for row vector.
Please, help. Thank you</p>sss dzu/matlabcentral/answers/contributors/3764851-sss-dzutag:nl.mathworks.com,2005:Question/1572952014-10-03T18:03:51Z2014-11-21T21:32:08Zsplitting a graph into a new one<p>Hello,</p><p>I have some data from my measurements and I have created three vectors 1x45000.
My Three vectors are x,F and t.
x is my displacement vector, F my force and t my time.</p><p>I want to do a subplot which I can do. I want the first subplot to be x vs t, the second subplot F vs t.</p><p>Then I would like to have some tools in my first subplot. I want to have some markers that I could adjust in the plot. I want to plot a third subplot with the data between these markers, but only F vs x.</p><p>How is this possible. I have no clue...</p><p>Thank you.</p>Daniel/matlabcentral/answers/contributors/3992396-danieltag:nl.mathworks.com,2005:Question/1637712014-11-21T20:51:59Z2014-11-21T21:29:10ZHow to remove certain point from a plot?<p>So I have a plot that shows some obvious outliers. I have identified those outliers value using the data cursor and there are three of them which are [3 29.03,17 25.21,23 57.49].</p><p>Now how do I remove them from my plot?</p><p>I know I can store the remaining good data into a new variable and plot them again, but how do I do that exactly?</p><p>Thanks!</p>Jessie/matlabcentral/answers/contributors/4711319-jessietag:nl.mathworks.com,2005:Question/1637752014-11-21T21:18:19Z2014-11-21T21:21:45ZHow to insert newline into displayed text in GUI?<p>I have a text box in my GUIDE-generated GUI in which I want to display the file that I just loaded (and read data from). I want it so that on the top line is just a file name, and on the next line it shows the path. I can't figure out how to insert a newline character into the string that I want to display. Somewhere on a forum site (perhaps this one) I saw someone suggest using the <tt>sprintf</tt> function like this:</p><pre class="language-matlab">string = sprintf([filename, '\n', pathname]);
</pre><pre class="language-matlab">set(handles.textbox,'String',string)
</pre><p>This WOULD work if only my filename and pathname did not have all sorts of special characters like underscores and backslashes. I tried escaping them by using the <tt>strrep</tt> function and replacing all underscores ---> '\_' and likewise any backslash ---> '\\'. Then I tried to do</p><pre class="language-matlab">string = sprintf([filename2, '\n', pathname2]);
</pre><p>where <tt>filename2</tt> and <tt>pathname2</tt> have been processed with <tt>strrep</tt> . But it fails to work! I continue to get an error when I try to run the GUI and display the loaded file into the textbox:</p><p><tt>Warning: Escape sequence '_' is not valid. See 'help sprintf'
for valid escape sequences.</tt></p><p>Any suggestions? Why is sprintf still screwing up with the underscore if I escaped it?</p>Alexei/matlabcentral/answers/contributors/5084669-alexeitag:nl.mathworks.com,2005:Question/1637742014-11-21T21:17:42Z2014-11-21T21:17:42ZWhich is the matlab directory for download of third parts software?<p>Hello guys, i'm installing the Raspberry pi support package for matlab. During this installation Matlab downloads also the Raspbian distribution. Where is this download on my pc? Where usually matlab puts downloads third parts software like this? I don't found the directory.</p><p>Thanks to all for the support.</p>squall141/matlabcentral/answers/contributors/5623433-squall141tag:nl.mathworks.com,2005:Question/1050212013-11-05T19:34:30Z2014-11-21T21:16:01ZHow can I find the percentage of the overlap of two histograms in Matlab?<p>I try to plot two histograms and I need to know quantitavely what is the area and percentage of overlap of these two histograms.</p>Zahra/matlabcentral/answers/contributors/4583895-zahratag:nl.mathworks.com,2005:Question/1473632014-08-12T21:02:08Z2014-11-21T20:57:36ZConflict between slx models and explorer in Windows 7<p>This has started really suddenly. I do not know what has changed.
I suddenly have some kind of massive conflict between windows 7 explorer, and relatively large (0.3MB or more) simulink library models (libraries).</p><p>The symptom is that in explorer if you try to do anything with these files (delete, copy, paste, access properties) it hangs the explorer window(s) using 100% of 4 cores, and the dreaded green progress bar of doom at the top. It takes perhaps 10 minutes to clear.</p><p>Specifically, I have slx library 2 files named something like "Roscoe_xxx_lib.slx" which have become almost unusable in Explorer today. Smaller slx files (models not libraries) do not seem to be affected. I thought I had some kind of virus or problem with windows indexing but I have tried everything with no effect.</p><p>EXCEPT, if I open Simulink without explorer, and manage to convert them back to the old ".mdl" extension, MATLAB renames the .slx as .slx.r2014. Now, I can copy, paste, move, delete those .mdl files without any problem.</p><p>I'll stress, there appears to be nothing wrong with MATLAB or Simulink. It is just some kind of really wierd interaction between those .slx libraries and explorer. You just can't move/copy/paste/delete them in explorer without minutes or hours of wait.</p><p>Any ideas? I notice that slx files seem to show some kind of thumbnail in explorer at the bottom when you click on them, even when you are in "Details" view. I see lots of web postings about windows 7 explorer hanging with media files with the green bar of death. Perhaps this is related to the "large" >0.3MB slx files?</p><p>Andrew</p>Andrew Roscoe/matlabcentral/answers/contributors/391499-andrew-roscoetag:nl.mathworks.com,2005:Question/1637722014-11-21T20:52:15Z2014-11-21T20:52:15ZComparing Two Empirical CDFs<p>Hi,</p><p>I have a problem where I want to compare an empirical CDF generated from simulation to another empirical CDF that comes from sampled data.</p><p>The shape of my simulated CDF changes based on a couple different parameters. I want to then optimize on these parameters in order to get the best match between the two empirical CDFs.</p><p>I'm a bit stumped on how to go about doing this. Searching around shows that the KS-Test is a good method for comparing empirical CDFs but the Matlab documentation seems to say that it can only be compared to a PD Object.</p><p>Any help would be great.</p><p>Thanks</p>Cole/matlabcentral/answers/contributors/5345198-coletag:nl.mathworks.com,2005:Question/1637692014-11-21T20:18:17Z2014-11-21T20:49:36ZLogical indexing for matrix<p>Hi Everybody!
I have difficulties with some logical indexing.</p><p>I have vector with time values. For example the date 1st january 2008 at 9:00:00 am would be</p><pre class="language-matlab">tvec=2008 1 1 9 0 0 and so on...
Tvec covers a whole year so it has 527040 rows and 6 columns.
</pre><p>How do I locate a specic period. For example 1st january 2008 from 9 to 10 am?</p><p>I tried this:</p><pre class="language-matlab">clear;clc;
period = [2008 1 1 9];
idx(:,1)=tvec(:,1)==period(1);
idx(:,2)=tvec(:,2)==period(2);
idx(:,3)=tvec(:,3)==period(3);
idx(:,4)=tvec(:,4)==period(4);
L=logical(idx);
tvec_a=tvec(L);
</pre><p>Thanks for any help you might have...</p>Jakob Hannibal/matlabcentral/answers/contributors/3657040-jakob-hannibaltag:nl.mathworks.com,2005:Question/1637702014-11-21T20:32:42Z2014-11-21T20:39:49ZHow to read an image or sprites in mfile?<p>I want to make a game by using images and sprites. But I dont know many functions to make use of them. Can anyone state any of the Matlab functions?</p>Ali/matlabcentral/answers/contributors/5601440-alitag:nl.mathworks.com,2005:Question/1080162013-11-29T12:54:55Z2014-11-21T20:33:24ZMex Compile failed, MATLAB 2013b<p>Hi,</p><p>I installed MATLAB 2013b on my Mac and when i try to run a simple simulink simulation, it fails. The versions installed on my computer are
MATLAB 2013b, Mavericks OS X 10.9, GCC 4.2.1, Xcode 5.0.2</p><p>Do i need to install anything else?</p><p>The following is the error that i get when i run the simple simulation</p><p>Applications/MATLAB_R2013b.app/bin/mex -c -O -DMATLAB_MEX_FILE -I/Applications/MATLAB_R2013b.app/extern/include -I/Applications/MATLAB_R2013b.app/simulink/include -I/Applications/MATLAB_R2013b.app/rtw/c/src -I/Applications/MATLAB_R2013b.app/stateflow/c/mex/include -I/Applications/MATLAB_R2013b.app/stateflow/c/debugger/include -I/Applications/MATLAB_R2013b.app/toolbox/stateflow/src/sf_runtime/export/include/sf_runtime Test1_sfun.c
/Users/muhammadsaleem/.matlab/R2013b/mexopts.sh: line 1: musal176#: command not found
/Users/muhammadsaleem/.matlab/R2013b/mexopts.sh: line 176: unexpected EOF while looking for matching `''
/Users/muhammadsaleem/.matlab/R2013b/mexopts.sh: line 205: syntax error: unexpected end of file
/Users/muhammadsaleem/.matlab/R2013b/mexopts.sh: line 1: musal176#: command not found
/Users/muhammadsaleem/.matlab/R2013b/mexopts.sh: line 176: unexpected EOF while looking for matching `''
/Users/muhammadsaleem/.matlab/R2013b/mexopts.sh: line 205: syntax error: unexpected end of file
/Applications/MATLAB_R2013b.app/bin/mexsh: line 1341: -c: command not found</p><pre> mex: compile of ' "Test1_sfun.c"' failed.</pre><p>gmake: <b>*</b> [Test1_sfun.o] Error 255</p><p>How do i fix this? Your help will be very appreciated. :o)</p><p>Best regards,
saleem</p>Saleem khan/matlabcentral/answers/contributors/2441199-saleem-khantag:nl.mathworks.com,2005:Question/1635952014-11-20T18:00:17Z2014-11-21T20:29:35ZHow do I match my colorbar scale to my contours on a map?<p>Hello,</p><p>I would like my colorbar scale to match my contours on a map (my contours are at 0,70,200 and 500m) but instead Matlab automatically divides the colorbar into 4 equal sections.</p><p>My code for the relevant section is below:</p><pre class="language-matlab">figure;
v=0,70,200,500;
contourf(LON,LAT,SRTM,v);
shading flat;
mesh(LON,LAT,SRTM);
map=[0 0 0.7
0 0 1
0 1 0
1 0 0];
colormap(map);
colorbar;
view(0,90);
</pre><p>I have looked online/ used Matlab help and I can limit the scale using "caxis([min max]);" but I also want to section the colorbar so it distinguishes 0-70m 70-200m 200-500m and 500+m.</p><p>Help appreciated.</p>Jacob/matlabcentral/answers/contributors/5890159-jacobtag:nl.mathworks.com,2005:Question/928132013-05-06T20:03:00Z2014-11-21T20:18:09ZHow do I increase the heap space for the Java VM in MATLAB 6.0 (R12) and later versions?<p>I am using a MATLAB version that is newer than MATLAB 6.0 (R12).*</p><p>How do I increase Java VM heap space?</p><ul><li>Note that the information in this solution is applicable to recent releases such as MATLAB 7.14 (R2012a).</li></ul>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:nl.mathworks.com,2005:Question/1627622014-11-14T21:27:00Z2014-11-21T20:14:57ZHow to make an interactive plot with or without GUI<p>Hi,</p><p>I have Three vectors, lets say they look like this:
time=[1 2 3 4 5 6 7 8 9 10];
position=[0.1 0.4 0.5 0.7 1 2 2.2 3.2 4 5];
force=[0 4 6 10 20 30 40 50 90 100];</p><p>I want to make a user interactive plot (GUI or not) with time on the x-axis and position and force on the y-axis.
But I want to add two markers or sliders in the plot so I can plot another plot with force vs position within a certain time interval that I choose with my markers or sliders from the first plot.</p><p>Some help is appreciated.
Thank you.
Daniel</p>Daniel/matlabcentral/answers/contributors/3992396-danieltag:nl.mathworks.com,2005:Question/1637672014-11-21T19:54:41Z2014-11-21T20:04:32ZI need switch case command to display two outputs with one input<p>I want wondering if switch case functions are able to put two different outputs with one input?
I have the problem when user enters '2' I want the output to become 697hz,1336hz. Or would i have to set up each individual number to an output?</p><p>This is my graph 1,2,3,697hz are in a column
1,4,7,* are in a row</p><pre class="language-matlab">1 2 3 697hz
4 5 6 770hz
7 8 9
* 0 #
1209hz,1336hz,
</pre><p>This is what I tried .</p><pre class="language-matlab">function [lowFrequency, highFrequency]=pushbutton_to_DTMF(string)
Number = input('enter #','s');
switch Number
case{'1','2','3'};
disp('697')
case{'1','4','7','*'}
disp('1209')
end
</pre>benny/matlabcentral/answers/contributors/5912234-bennytag:nl.mathworks.com,2005:Question/1637662014-11-21T19:53:27Z2014-11-21T19:53:27ZWavelet Transform energy preservation<p>Some brief understanding of this topic is required as I describe my problem.
In Wavelet image compression, one has two main components: an image and a Wavelet matrix.
An important property of wavelets is that its inverse is also its transpose.
Here are the matrices we're using
* I=('kochflake.png');
* T1 is a 256x256 matrix whose inverse is its transpose
* W=T1*double(I)*transpose(T1);
When we compute W, we are not supposed to lose or gain energy.
Here is our problem. Images are often of type uint8, and when computing many (large) numbers, the computer asks that the data be converted to double. I have tested these two different types and found that they have different energies.</p><p>*energy is defined as the sum of the squared elements of a matrix.</p><p>For image compression, this understanding is key in reducing data space required by the computer. So we come down to two unique problems:</p><p>#1 Which sumsqr algorithm is the correct one? uint8 method or double?
#2 Why, when we run the program, do we get different energies for I and W?</p>Brian/matlabcentral/answers/contributors/5771796-briantag:nl.mathworks.com,2005:Question/1637652014-11-21T19:53:00Z2014-11-21T19:53:00ZSVM convergence info objective function value - can I use it for feature selection? <p>Hello..,
I am trying to select the best features by giving some scores to the features by training the data with support vectors of individual features and looking at the margin or objective function. This is explained in the attached paper. According to that, after training, each single feature combination is associated with a margin value and group of support vectors. Then the feature with "Smallest margin" (or should it be minimum objective function?) is chosen as the best single feature. (page V-799 of the paper).</p><p>My question is, for above check, can I use the objective function value that is given in SVM convergence info after running MATLAB fitcsvm ? Usually objective function value is negative. Should I consider the only the magnitude in this case?</p><p>Thanks so much
Greatly appreciate your time
Regards
janaka</p>Janaka/matlabcentral/answers/contributors/626821-janakatag:nl.mathworks.com,2005:Question/1637622014-11-21T18:59:30Z2014-11-21T19:50:58Zunexpected shift after downsampling using decimate<pre class="language-matlab">n = 1000;
t = 1:n;
x = rand(1,n) - 0.5;
x = sin(2*pi/100*t);
y = decimate(x,4);
figure('color','w');
ha = axes('nextplot','add','box','on');
plot(ha,t,x,'k','marker','.');
plot(ha,t(1:4:end),y,'r','marker','o'); addkeycb;
</pre><p>There is a shift of 3 points.</p><img src = "/matlabcentral/answers/uploaded_files/21485/QQ%E6%88%AA%E5%9B%BE20141121195849.png">Ray Lee/matlabcentral/answers/contributors/1411057-ray-leetag:nl.mathworks.com,2005:Question/1634662014-11-19T23:07:44Z2014-11-21T19:37:17Zhow to create continuous variables<p>hello all :</p><p>I need to run a loop for 10000 times and in every iteration, i get an array of values. I need to assign this array of values to a different variable(A1, A2 ,A3,A4,...) in every iteration. what conditions should i use to create the variables ion the same loop?</p>uic/matlabcentral/answers/contributors/5698101-uictag:nl.mathworks.com,2005:Question/1637642014-11-21T19:08:40Z2014-11-21T19:36:42ZHow do i convert an image plot to a matrix.<p>I was wondering if it was possible to create a matrix out of a figure plot.</p><p>I would be grateful for any help. Thanks.</p>ronald/matlabcentral/answers/contributors/4477648-ronaldtag:nl.mathworks.com,2005:Question/1637182014-11-21T11:48:27Z2014-11-21T19:31:37ZHow to estimate the Gaussain kernel based on spatial bandwidth for KDE<p>Hi,</p><p>I want to use bandwidth h= 10 to estimate Gaussian Kernel</p><p>Not sure how to use it for each point</p><p>please advice</p>Tania/matlabcentral/answers/contributors/5892299-taniatag:nl.mathworks.com,2005:Question/1637112014-11-21T10:36:51Z2014-11-21T19:29:26ZIs it possible to get an exitflag using findop ?<p>I am using 'findop' from the Simulink Control Design Toolbox to find operating points of a system. I use the default 'graddescent_elim' algorithm, which calls the 'fmincon' algorithm.</p><p>I know that the 'fmincon' function can return an integer 'exitflag' giving informations about how the optimization has ended.
In the report generated by findop ('opreport') I can display a termination message with the command 'opreport.OptimizationOutput.message' which gives informations about the termination of the optimization. However I would like to have that info "summed up" as an integer like the 'exitflag' of 'fmincon'.
Is it possible to get the 'exitflag' of fmincon as an output of 'findop' ?</p>ThS/matlabcentral/answers/contributors/4750814-thstag:nl.mathworks.com,2005:Question/1636252014-11-20T21:55:11Z2014-11-21T19:21:38ZHow to enlarge legend marker size in r2014b?<p>In previous versions one could grab the children of the legend object to change their size individually but now those don't exist anymore. How can I present larger markers in the legend that correspond to tiny scatter dots?</p><p>thanks!</p>Michelle Tadmor/matlabcentral/answers/contributors/3320168-michelle-tadmortag:nl.mathworks.com,2005:Question/1634382014-11-19T18:38:08Z2014-11-21T19:21:29ZParpool local too slow<p>Why does it take so long to start a parallel pool on a local profile? It's only 10 seconds or so, but for a job that should simply thread across the cores of the host machine's CPU it should be nearly instantaneous.</p><p>I spent some time reworking a bit of code we use frequently to run in parallel. The runtime went from 10 seconds to around 2 which I was very happy with. Our use case, though, only requires running a few jobs at a time. Over time it would add up to a pretty nice time savings except that every time the user runs the code they need to wait for parpool to run. The 15 seconds there means that it's only worth using the parallel code I worked so hard on if they're going to be running more than a handful of jobs at a time which is rare. The result is that my time producing parallel code was wasted because Matlab inexplicably needs time to set up a pool of workers on the host machine that Matlab itself is running on. Is there any way around this because it makes no sense?</p>Carl/matlabcentral/answers/contributors/4512437-carl