http://www.mathworks.de/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2014-10-30T14:27:40Ztag:www.mathworks.de,2005:Question/1607032014-10-30T14:27:40Z2014-10-30T14:27:40ZCompile version of program doesn't recognise a file location<p>I created a function to write text to a file in the folder where the matlab file is running. It works fine. but when I compile it, its askign for the file to be in my users\apdata etc folder. How do I get around this as I want to share it and don't want the users to have to do this?</p><p>function pathtext = WriteFileToActingDir(hObject, eventdata, handles,text, file )
%Write String 'text' to a file 'file' in the current operating directory
% Detailed explanation goes here</p><pre> prog = mfilename('fullpath'); %Get current program path & name
[progpath,name,ext] = fileparts(prog); %Split out folderpath
pathtext = fullfile(progpath,file); %Build new filename
fid = fopen(pathtext, 'w');
fprintf(fid, '%s', text);
fclose(fid);
end</pre>Jason/matlabcentral/answers/contributors/1217570-jasontag:www.mathworks.de,2005:Question/1604942014-10-28T23:21:34Z2014-10-30T14:23:48ZQuestion about parforloop in matlab<p>Hi,
I am using parfor loop on matlab. However, I am having troubles with printing to a file using fprintf command. I am getting the following error:</p><pre class="language-matlab">Invalid file identifier. Use fopen to generate a valid file identifier.
</pre><p>Please Help!</p><p>Here's my code:</p><pre class="language-matlab">tic
i = 1;
fID = fopen('datafile7.txt', 'W');
fprintf(fID,'name\trow\tcolumn\t25R\t25G\t25B\t1R\t1G\t1B);
s = ['photo000' int2str(i) '.jpg'];
A=imread(s);
[m,n,rgb]=size(A);
for row=4:(m-3)
parfor column=4:(n-3)
</pre><pre class="language-matlab">fprintf(fID, 'image%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t\r\n',i,row,column,A(row-3:row+3,column-3:column+3,1), A(row-3:row+3,column-3:column+3,2), A(row-3:row+3,column-3:column+3,3) );
</pre><pre> end
end</pre><pre class="language-matlab">fclose(fID);
toc
</pre>John/matlabcentral/answers/contributors/4336106-johntag:www.mathworks.de,2005:Question/1607022014-10-30T14:18:59Z2014-10-30T14:18:59Zs function builder through comment line<p>Hi</p><p>I just want to know how to set the s function builder block parameters through Matlab comments.</p><p>For example : I want add on input port in my s function builder block. I’ll go directly Data Properties pane and click add and I’ll give my own names to my input variable.</p><p>Consider the same operation I just want to do in programmatically through matlab comments. If give same sample code it’s healthier to my understating.</p><p>Regards,
Sri Prakash Muni</p>sri prakash muniyandi/matlabcentral/answers/contributors/2737432-sri-prakash-muniyanditag:www.mathworks.de,2005:Question/1605352014-10-29T09:28:55Z2014-10-30T14:14:02ZMATLAB interface instrument driver<p>hey,</p><p>i am now try to connect the r&s zvb, a vector network analyzer to the matlab via gpib, I could succesfully create an interafce object and communicate through the interface. But I receive a error message, when I want to use the Matlab interface driver (.mdd file generated from Vxi Plug& paly driver i download from the r&s offical website). see code below for the error message.</p><p>d=icdevice('custom_matlab_rszvb_driver_3.12.0.mdd','GPIB::0::20::0::INSTR')
Error using icdevice (line 233)
The VXIplug&play driver referenced in C:\Program
Files\MATLAB\R2014a\toolbox\instrument\instrument\drivers\custom_matlab_rszvb_driver_3.12.0.mdd
cannot be found.</p><p>i have add the 'custom_matlab_rszvb_driver_3.12.0.mdd' into the C:\Program
Files\MATLAB\R2014a\toolbox\instrument\instrument\drivers' and i am sure the the VISA Resource Address 'GPIB::0::20::0::INSTR' is correct.</p><p>any help? thanks.</p>jiao/matlabcentral/answers/contributors/5834857-jiaotag:www.mathworks.de,2005:Question/1606962014-10-30T12:14:40Z2014-10-30T14:03:11ZCan this be vectorized?<p>Dear all,</p><p>I have two vectors A and B of respective sizes na and nb, with na>=nb. All elements in B are unique while the elements in A are not. But all elements in A are in B. I would like to create a mapping between A and B and one way to do that is as follows:</p><pre class="language-matlab">A=nan(na,1);
for ii=1:nb
A(A==B(ii))=ii;
end
</pre><p>This works well be becomes prohibitively expensive for large na. And so my question is whether there is a way of getting rid of the for loop and/or creating this mapping differently.</p><p>Thanks,</p><p>P.</p>Patrick Mboma/matlabcentral/answers/contributors/1075584-patrick-mbomatag:www.mathworks.de,2005:Question/1602762014-10-27T15:26:50Z2014-10-30T14:01:17Zquestion about pause function,and real time drawing<p>Hello!</p><p>I use a drawing tablet and i manage to get and save x,y coordinates.</p><p>if i want to see what i draw, i use the command</p><p>line(x, y, 'Color','k','LineWidth', 1);</p><p>If i want to see in real time what i am drawing i use</p><p>line(x, y, 'Color','k','LineWidth', 1);</p><p>pause(0.001);hold on</p><p>The problem is when i use pause, i miss some packets from the tablet,so the drawing is kind of squared and it is different from the non real time drawing.</p><p>Any idea what to do at the real time drawing?</p><p>Thank you very much!</p>alex/matlabcentral/answers/contributors/5030888-alextag:www.mathworks.de,2005:Question/1606982014-10-30T13:19:26Z2014-10-30T13:49:19Zhow can i evaluate e^x using maclaurin expansion?<p>I already have the factorial function</p>Constandinos/matlabcentral/answers/contributors/5840428-constandinostag:www.mathworks.de,2005:Question/1607002014-10-30T13:35:12Z2014-10-30T13:42:30ZHow to write a for loop inside an if loop<p>I am using simulink user defined function for the control applications. The code does not execute correctly, only the first line executes and remaining code is not getting executing. The code is shown below:</p><p>function [Vo,ftw,Rc_ctrl,Dir] = fcn(C,S0,S1,S2)</p><pre> Vo = 0.20; ftw = 10; Rc_ctrl = 0; Dir = 0;</pre><pre> if (S0 == 1) && (S1 == 1) && (S2 == 1) && (C <= 2000000)</pre><pre> for i=2000000:50000:3500000
if ( (C > i) && (C <= i+50000))
Vo = Vo+0.02; ftw = ftw+1; Rc_ctrl = 0; Dir = 0;
end
end
end</pre><p>The variable C is a counter input which counts from 0 to 3500000 at an increment step of 50000. The function inputs S0,S1,S2 are input to the user defined function.</p><p>While executing the code only first line executes and remaining lines not getting executing.</p><p>Thanking you in advance for your valuable suggestions !!!</p><p>Roy</p>Roy Francis/matlabcentral/answers/contributors/953414-roy-francistag:www.mathworks.de,2005:Question/1603352014-10-28T00:53:01Z2014-10-30T13:38:54ZYOSEMITE MATLAB R2013a PATCH ISSUE<p>So I upgraded to yosemite and did the link and added the patch to my MATLAB student version, Specifically R2013a_patch_1098655.dmg. I complete the steps and at the end it says Patch Complete. But then when i try to launch MATLAB it still says the same message and does not open an says "You cant use the version of the application 'MATLAB_R2013a_Student' with this version of OS X(You have 'MATLAB_R2013a_Student' R2013a (8.1.0).</p><p>PLEASE HELP!</p>Adam/matlabcentral/answers/contributors/4519126-adamtag:www.mathworks.de,2005:Question/1606992014-10-30T13:28:26Z2014-10-30T13:28:26Zfunction call mistake while fft calculation<p>Hello,
I am calculating harmonics, THD etc. for plotted signals.
I defined a button which calls a function to calculate some parameters. This function callss another one to calcualte fft and related things.</p><p>I defiend my button like this:
pb1 = uicontrol('Style','pushbutton','String','plot FFT','Callback','plot_fft(x,ASM_6ph_voltages.signals.values(:,7),max_step,f_fundamental)');
Here x is defined as time vector.</p><p>Then in plot_fft function it calculates some parameters and calls the fft_synth function.</p><p>If I push the button on the graph it doesn't work. But when I start the plot_fft function in command window, it works.</p><p>What may be the reason?
Thank you very much in advance.</p>Mehmet/matlabcentral/answers/contributors/5485862-mehmettag:www.mathworks.de,2005:Question/1601132014-10-26T06:06:33Z2014-10-30T13:13:46ZCreating a function to plot multiple column of a variable in workspace<p>I have a array which is 729 by 9</p><p>.</p><p>.</p><img src = "/matlabcentral/answers/uploaded_files/19997/array.jpg"><p>.</p><p>.</p><p>Currently I am plotting the different columns in the same plot using the follow command:</p><p>.</p><pre class="language-matlab">plot(wavelengtha(:,1), Raman);
</pre><pre class="language-matlab">hold on;
</pre><pre class="language-matlab">plot(wavelengtha(:,2), Raman);
</pre><pre class="language-matlab">hold on;
</pre><pre class="language-matlab">plot(wavelengtha(:,3), Raman);
</pre><pre class="language-matlab">hold on;
</pre><pre class="language-matlab">plot(wavelengtha(:,4), Raman);
</pre><pre class="language-matlab">hold on;
</pre><pre class="language-matlab">.
</pre><p>.</p><p>.</p><p>.</p><pre class="language-matlab">plot(wavelengtha(:,9), Raman);
</pre><p>.</p><p>.
This is still manageable as its only 9 columns. however in later stage, I will have arrays stretching up to 100+ columns. I was thinking of putting the above code in function. Where I will then key in the name of the variable to plot all the columns as y-axis.</p><p>.
Can Someone help me with this?</p>ZONG YI Ng/matlabcentral/answers/contributors/5751907-zong-yi-ngtag:www.mathworks.de,2005:Question/1606742014-10-30T09:04:47Z2014-10-30T13:07:30ZHow can I get another window after clicking on the push button?<p>I am making a tictactoe game. At first a window will come asking for the players' name. Then when the push button written "play" on it is clicked the window will change i.e. the window containing the game's plot will come.</p>Afsana Chowdhury/matlabcentral/answers/contributors/5839493-afsana-chowdhurytag:www.mathworks.de,2005:Question/1377722014-06-26T14:14:10Z2014-10-30T13:05:09ZHow can i create a NetCDF file ?<p>I'm trying to create a NetCDF file using netcdf.create ou nccreate but i'm not getting.</p><p>When i try to use netcdf.create:</p><p>>> netcdf.create('file','netcdf4');
??? Error using ==> netcdflib
Unrecognized operation: "NETCDF4"</p><p>Error in ==> getConstant at 28
param = netcdflib('parameter', param_name);</p><p>Error in ==> create at 45
mode = netcdf.getConstant(mode);</p><p>If you can help me i will be greatfull.
Thanks.</p>Felipe/matlabcentral/answers/contributors/5355264-felipetag:www.mathworks.de,2005:Question/1598542014-10-23T17:07:38Z2014-10-30T13:02:06Zcurve fit toolbox help system ODE and excel?<p>Hi, I am trying to curve fit using the toolbox to a function which is a system of ODE. my data corresponds to one equation of the function. how can i specify this? Also, the tutorial seems to say you should put your data into the command line, but mine is in excel, is there some easier way? Thanks!</p>Renee/matlabcentral/answers/contributors/5776429-reneetag:www.mathworks.de,2005:Question/1606202014-10-29T21:32:18Z2014-10-30T12:57:12ZHow to call a function with rows of a matrix?<p>Hey,</p><p>I would like to vectorize a function call that I call with rows of a matrix. How can I implement it without a for loop?</p><p>Thanks.</p>UCL student/matlabcentral/answers/contributors/4746756-ucl-studenttag:www.mathworks.de,2005:Question/1606812014-10-30T09:49:13Z2014-10-30T12:54:58Zcalculating dual quaternion from two vectors<p>hi,
i have two points (vectors) and i would like to calculate the rotation between them using quaternions.
as i understand quaternion only give me the rotation, there fore if there is a translation between the two points as well the results i would get for the rotation angles are not good.
i have read that to represent a rotation and translation using quaternion i need to uses the dual quaternion.
i know how to calculate a quaternion between two points and then extract the rotation angles:</p><pre> p1 = [1,0,0]; p2 = [0,1,0];
u = cross(p1,p2)/norm(cross(p1,p2));
alpha = acos(dot(p1,p2)/(norm(p1)*norm(p2)));
q = [cos(alpha/2), sin(alpha/2)*u(1), sin(alpha/2)*u(2), sin(alpha/2)*u(3)]
[roll, pitch, yaw] = quat2angle(q,'XYZ') </pre><p>the question is how do i calculate a dual quaternion between two points?</p><p>thank you for your help.</p>Dany/matlabcentral/answers/contributors/3499251-danytag:www.mathworks.de,2005:Question/1553172014-09-18T15:17:06Z2014-10-30T12:54:04ZReorder table variables / columns<p>I've created a table from a large csv file using the readtable function.
I want to reorder the variables / columns in this table.</p><p>For example.</p><p>My table's name is CUTable</p><p>It has a variable CUTable.Date which is the date the data was taken
It is currently column 20 in the table.
I want to make it column 2 and shift existing columns 2-19 to 3-20.</p><p>It seems there should be a very easy command to do this which I'm missing, but I can't seem to find it anywhere in the help or these forums. I could, but don't want to "brute force" it (e.g. create a new table, and one-by-one copy the variables from the exiting table to the new table in the order I want, then delete the old table) if avoidable.</p><p>How can I accomplish this?</p>Alan/matlabcentral/answers/contributors/3622143-alantag:www.mathworks.de,2005:Question/7092011-02-02T13:06:14Z2014-10-30T12:53:23Z'not enough storage' error on xlsread<p>Matlab 2010a
Windows XP (running under VMWare on a Linux workstation)</p>
<p>I'm trying to read an excel sheet of about 60,000 x 75 values, 21MB file size, using xlsread. I get "??? Error: Not enough storage is available to complete this operation." The Excel file has several sheets in it, but the 60k x 75 is the largest. After some experimentation, here are my observations:</p>
<p>1. I have no problem creating arrays of this size directly from Matlab. This would imply it's not scritcly a memory problem with the resulting array size.</p>
<p>2. I am able to read a different Excel file whose largest sheet is 60k x 21 with no problem. The file in question also has a 60k x 21 sheet, but if I try to read it by specifying the worksheet, it fails, even though I know it can handle 60k x 21. This seems to imply that either the function is always reading the entire file, even when I specify a smaller worksheet, or the file size itself is a factor, even if I'm only trying to read a small subset of the data.</p>
<p>3. If I specify a cell range in the xlsread so I'm reading a subset of the 60k x 75 worksheet, it will work (up to a point of course). If I specify the entire 60k x 75 range, it will fail, as you would expect. Contrary to 2, this seems to imply that the total file size is NOT a factor, only the amount of data you actually want to read. I can also read the data in two steps by specifying the first 30k rows then doing a second read for the last 30k rows and concatenating the resulting arrays back into one.</p>
<p>4. I've had mixed results taking a file that has failed the read and reducing it in size. In one case I reduced a file (by deleting sheets and columns) down to 60k x 21 values in a 4MB file, but the xlsread still failed, even though I can read 60k x 50 from another file with multiple worksheets totaling 16 MB. In other cases, I can take a file that was failing, delete rows and/or sheets, and the xlsread works. Don't know what to make of this.</p>
<p>If it helps, the memory Matlab reports is:
>> [uv sv] = memory</p>
<pre class="language-matlab">uv =
</pre>
<pre> MaxPossibleArrayBytes: 150216704
MemAvailableAllArrays: 784936960
MemUsedMATLAB: 969478144</pre>
<pre class="language-matlab">sv =
</pre>
<pre> VirtualAddressSpace: [1x1 struct]
SystemMemory: [1x1 struct]
PhysicalMemory: [1x1 struct]</pre>
<pre class="language-matlab">>> sv.VirtualAddressSpace
</pre>
<pre class="language-matlab">ans =
</pre>
<pre> Available: 784936960
Total: 2.1474e+009</pre>
<pre class="language-matlab">>> sv.SystemMemory
</pre>
<pre class="language-matlab">ans =
</pre>
<pre> Available: 3.2114e+009</pre>
<pre class="language-matlab">>> sv.PhysicalMemory
</pre>
<pre class="language-matlab">ans =
</pre>
<pre> Available: 1.5888e+009
Total: 3.2081e+009</pre>
<p>According to the Matlab help and the memory info, I should be able to make a single array on the order of 18 million values, and 60k x 75 is nowhere near that.</p>
<p>Does anyone have experience reading large spreadsheets using xlsread? Is there a way to force it to use single precision instead of double? I don't actually need to use the full 60k x 292 array, but I was hoping to have Matlab delete rows based on the value in a certain column rather than trying to specify to xlsread a data range to read. Any advice is much appreciated!</p>Jason/matlabcentral/answers/contributors/2712625-jasontag:www.mathworks.de,2005:Question/1605272014-10-29T08:26:31Z2014-10-30T12:50:52Zi cannot make mex setup command to work on my matla2012a?<p>hello all, i am trying to use mex setup command on matlab 2012a but it does not work on my laptop, and i get the error "Previously accessible file "C:\Program Files\MATLAB\R2012a\toolbox\matlab\iofun\tempname.m" is now inaccessible." any ideas??</p>bena/matlabcentral/answers/contributors/5002427-benatag:www.mathworks.de,2005:Question/1606842014-10-30T10:04:22Z2014-10-30T12:47:58ZHow can i detect car using tail light color and shape of the car?<p>I m working on car detection from a given image. I m thinking about using tail light color and shape of the rear side of car as my feature. I used color segmentation and edge detection. now i m stuck with classification. I can't use SVM as my supervisor won't allow SVM. What can i do?
I attached my color segmentation and edge detection code. Also an image of car.</p><img src = "/matlabcentral/answers/uploaded_files/20212/car10.jpg">Nahid Islam/matlabcentral/answers/contributors/5321460-nahid-islamtag:www.mathworks.de,2005:Question/1604462014-10-28T17:07:10Z2014-10-30T12:45:38Zhow to transform my input in n-dimensions<p>Dear All,</p><p>I need to rotate hyper-rectangle in n-dimensions so I wrote this after generating the lengths</p><pre class="language-matlab">L= lengths;
</pre><pre class="language-matlab">v=perms([L]/2,'signs');
size(v); % size 16x4
pp=mean(v, 1);
v = bsxfun(@minus, v, mean(v, 1));
sca = createScalingBox(L); %general formula for scaling
for j=1:m
Angle=(pi/2)*rand(2,m+1); % general formula for rotation matrix
end
ndRotate=ndrotate(Angle)
</pre><pre class="language-matlab">tra = createTranslationBox3d([C]); general formula for translation
trans = tra * ndRotate * sca;
TSIZE_B=size(16,4);
TDIMS_A=4;
TDIMS_B=4;
R = makeresampler('linear', 'fill');
tform = maketform('affine', trans);
B = tformarray(v, R,tform, TDIMS_A,TDIMS_B,TSIZE_B, [], 0);
</pre><p>but I got error Error using maketform>validate_matrix (line 317)
The final column of A must consist of zeroes, except for a one in the last row.
Error in maketform>affine (line 163)
A = validate_matrix( A, 'affine' );</p><p>I want to transform the matrix v which is of size 16x4 and their is no zeroes final column in v so how can I use the next command so I can got 4 columns for the outputs X=[x y z f] and I need to do it general formula for n>=4 can anyone help me</p><p>regards</p>imola/matlabcentral/answers/contributors/5505761-imolatag:www.mathworks.de,2005:Question/1606732014-10-30T09:01:06Z2014-10-30T12:43:31ZGreek symbols (esp. µ) not italic<p>I want to use the greek "mu" to be displayed non-italic.
Example:
ylabel('c [\mu mol/l]')</p><p>Is there any easy solution to this problem?</p>lee/matlabcentral/answers/contributors/5839486-leetag:www.mathworks.de,2005:Question/1606312014-10-29T23:32:22Z2014-10-30T12:41:02ZPass one value at a time from a matrix to a for loop<p>Hi,</p><p>I need to pass one value at a time from matrix to iprev inside the for loop. For example, first value of iprev is 11 then 19 and so on. How can I modify my code to do that?</p><pre class="language-matlab">matrix=[11 19 21 29 37 31 45 47 48 54 60 57 66 67 69 86 84 89 111 113 117 120 122 128 139 143 152 161 161 165 170 170];
</pre><pre class="language-matlab">isemp = all(isnan(ave),1);
for ii = find(isemp)
ave(:,ii) = ave(:,iprev);
end
</pre><p>Any help is appreciated.</p><p>Thanks in advance.</p>Damith/matlabcentral/answers/contributors/5131512-damithtag:www.mathworks.de,2005:Question/1603102014-10-27T19:38:49Z2014-10-30T12:39:44ZDynamic Variables in Loops<p>I'm sure this has been answered before, but I can't seem to find the answer anywhere... Pretty simple problem for seasoned MATLAB users...</p><p>I have a series of images in a folder. I am trying to average these images. I start off by prompting the user for a folder to work from, then count the number of .jpg's in the folder. I run a loop to create a variable A for each image in the folder (A1, A2, A3, ....., A(i))</p><p>Now I need to assign those images to A(i) for them to processed.</p><p>Here is the code, thanks in advance. It is NOT recognizing A(i) (I think) and the error message is</p><p>Error in Average_Code (line 21)
A(i)=imread(Files(i).name);</p><pre class="language-matlab">clc;
clear all;
close all;
</pre><pre class="language-matlab">%User selecting image directory
cd(uigetdir);
</pre><pre class="language-matlab">%Counting number of .JPG's in folder
Files = dir('*.jpg')
b=numel(Files);
</pre><pre class="language-matlab">%Create Dynamic Variables
for i=1:b
eval(['A' num2str(i) '= i']);
end
</pre><pre class="language-matlab">fusion = 0;
</pre><pre class="language-matlab">%Assign Images to Dynamic Variables
for i=1:b
A(i)=imread(Files(i).name);
A(i)=double(A(i));
fusion = fusion + A(i);
end
</pre><pre class="language-matlab">%Average Images
</pre><pre class="language-matlab">average_image = fusion/b;
imshow(average_image);
</pre><p>Thoughts?</p>Shant/matlabcentral/answers/contributors/3912945-shanttag:www.mathworks.de,2005:Question/1585592014-10-14T11:18:04Z2014-10-30T12:37:42ZHow to get and residual energy for cluster head and cluster member ?<p><a href = "http://www.mathworks.in/matlabcentral/answers/153186#comment_235285">http://www.mathworks.in/matlabcentral/answers/153186#comment_235285</a> sir from your code i can get an cluster head and cluster head members. But i want to get their residual energy also ('energy'(S.E in my code)).For every node i want.(i need both cluster head and cluster member energy).</p>Arul prasath/matlabcentral/answers/contributors/4647176-arul-prasathtag:www.mathworks.de,2005:Question/1606972014-10-30T12:15:23Z2014-10-30T12:32:53ZHow to save fvtool diagram as a matlab figure??<p>Hi guys,</p><p>I am new with this staff and have a problem about saving fvtool Magnitude Response plot as matlab figure.</p><p>You can export it as image formats(.jpeg, .png,.. ) but not in ".fig"</p><p>Anyone can help me?</p><p>Here is simple fvtool code;</p><pre> filter_4_t =[0.2018 0.1189 0.1793 0.1793 0.1189 0.2018];
filter_5_t =[0.1716 0.1300 0.1984 0.1984 0.1300 0.1716];
filter_4_c =[0.2260 0.0772 0.1968 0.1968 0.0772 0.2260];
filter_5_c =[0.1921 0.0960 0.2119 0.2119 0.0960 0.1921];
bode=fvtool(filter_4_t,1,filter_5_t,1,filter_4_c,1,filter_5_c,1,'Fs',50);
legend(bode,'Taylor4','Taylor5','Chebyshev4','Chebyshev5');</pre><p>I want to save the bode diagram as a figure.</p><p>Is there any way to do it?</p>ozgur/matlabcentral/answers/contributors/3577870-ozgurtag:www.mathworks.de,2005:Question/1606382014-10-30T01:28:16Z2014-10-30T12:31:34ZHi I want to plot the transcendental equation for dielectric waveguide the equation for that is <p>tan(x)=sqrt(v^2-x^2)/x where v is 8.219. the hand made plot is in the figure I know the basics but still couldn't figure out. any help would be appreciated.</p>Neel/matlabcentral/answers/contributors/5838461-neeltag:www.mathworks.de,2005:Question/27712011-03-08T19:48:53Z2014-10-30T12:28:32Zhow to use a C++ program to call a Matlab script<p>How to call a matlab script from an C++ program (not visual C) on Linux Red Hat.
How easy is it to do this? What are the steps? How do I code C++ to invoke the script? How do I compile the C++ to create an executable? Can someone answer this? Is this supported on Red Hat Linux 5.5? Thanks.</p>Lara/matlabcentral/answers/contributors/2773035-laratag:www.mathworks.de,2005:Question/921242013-05-07T16:16:00Z2014-10-30T12:23:00ZWhy am I unable to use matlabpool or parpool with the local scheduler or validate my local configuration of Parallel Computing Toolbox?<p>When attempting to use matlabpool or parpool in Parallel Computing Toolbox, it will not open or I receive an error message. As well, I am unable to validate my local scheduler profile.</p><p>I am not connecting to a cluster. How can I get the local scheduler to work?</p>MathWorks Support Team/matlabcentral/answers/contributors/4622813-mathworks-support-teamtag:www.mathworks.de,2005:Question/1605992014-10-29T18:17:58Z2014-10-30T12:22:24ZError: Activation cannot proceed. (R2014b)<p>I have installed Matlab 2014b on a node of a cluster but failed to launch the software ( <tt>matlab14</tt> is an alias to <tt>/usr/local/MATLAB/R2014b/bin/matlab</tt>):</p><pre class="language-matlab">root@trunks:/usr/local/MATLAB/R2014b/bin# matlab14
MATLAB is selecting SOFTWARE OPENGL rendering.
root@trunks:/usr/local/MATLAB/R2014b/bin# ---------------------------------------------------------------------------
Error: Activation cannot proceed. You may either:
1. Set an X11 display, and restart the activation process
2. Use the silent activation feature
3. Activate using the license center
</pre><p>While prior to that I had already activated, sucessfully:</p><pre class="language-matlab">root@trunks:/usr/local/MATLAB/R2014b/bin# ./activate_matlab.sh -propertiesFile /home/users/khue/Matlab/R2014b/activate.ini
Silent activation succeeded.
</pre><p>I tried for another user (not root) with a different license file but still failed.</p><p>Thank you in advance for any suggestions.</p>Khue/matlabcentral/answers/contributors/4693654-khuetag:www.mathworks.de,2005:Question/1606882014-10-30T11:12:15Z2014-10-30T12:16:45ZIndexing concatenated matricies without changing the order<p>I'm attempting to index an outputted matricy from one function into a bigger matricy.
My code at the moment:</p><pre> % code
while j <= length(sec)
y=sec(j,:);
[max,~]=coros(y,thershold,x);
maxbox = [maxbox;max];
j=j+1;
end</pre><p>The output max finds the largest values in a data set and outputs it as a matricy [x y]. Sample output:</p><pre class="language-matlab">if true
3 10
5 12
9 15
end
</pre><p>I then use maxbox = [maxbox;max]; to concatenate the matricies.
I'd like to have each output correspond to the value of j it was found at. So that I know when they occur as well as where they occur. (j being time).</p><p>Sample of desired output:</p><pre class="language-matlab">if true
j 3 10
j 5 12
j 9 15
end
</pre><p>Before I concatenate it with the next matricy of values at j+1.
Help is appreciated!
Thanks.</p>Elia/matlabcentral/answers/contributors/5444752-eliatag:www.mathworks.de,2005:Question/1606942014-10-30T12:10:56Z2014-10-30T12:14:45Zi want to know how i can get (h) in exepression by matlab code<p>i want to get the equation which at picture
to can get (h)
or how i can get gamma inverse</p>ahmed/matlabcentral/answers/contributors/3925044-ahmedtag:www.mathworks.de,2005:Question/1606952014-10-30T12:14:38Z2014-10-30T12:14:38ZFourier Series Function, Coefficients and Graph<p>Hi,</p><p>Please could you help me answer the following question:</p><p>f(x) = 2, -2<x<0</p><pre> 2-x, 0<x<2</pre><p>I need to find the coefficients of the first 5 harmonics.</p><p>I then need to plot the function and the 5 term fourier series (n=5).</p><p>Lastly I need to sketch the Fourier series (not the 5 term approximation) over the interval -6<=x<=6</p><p>Thanks in advance!</p>Bob Jackson/matlabcentral/answers/contributors/5824109-bob-jacksontag:www.mathworks.de,2005:Question/1606932014-10-30T12:08:23Z2014-10-30T12:08:23Zwhat i get only zero's in the cell array?<img src = "/matlabcentral/answers/uploaded_files/20221/%D7%91%D7%A2%D7%99%D7%99%D7%94%201.jpg"><p>in the image you may see that for some reson integ(i) gets only 0 values. whay is that?
in the look it should get the previous values + the valuse of the integral calculation?</p><p>how can i fix that code so it will work properly?</p>JACK/matlabcentral/answers/contributors/5810442-jacktag:www.mathworks.de,2005:Question/1584612014-10-13T15:21:41Z2014-10-30T12:07:08ZHow do I combine two cell arrays into one cell array?<pre> >> Q{1}
ans =
'4400002970000003533'
'4400002970000003533'
'4400002970000003535'
'4400002970000003536'
'4400002970000003533'
'4400002970000003532'
'4400002970000003537'</pre><pre> >> Q{2}
ans =
'4400002890000146180'
'4400002890000146180'
'4400002970000000026'</pre><p>I want to get a new cell:</p><pre> '4400002970000003533'
'4400002970000003533'
'4400002970000003535'
'4400002970000003536'
'4400002970000003533'
'4400002970000003532'
'4400002970000003537'
'4400002890000146180'
'4400002890000146180'
'4400002970000000026'</pre><p>I don't want to use the function <tt>cell2mat</tt>, because it is too slow for my program. Do you have any good ideas?</p>pengcheng/matlabcentral/answers/contributors/5712283-pengchengtag:www.mathworks.de,2005:Question/1606362014-10-30T00:29:38Z2014-10-30T12:03:37ZConvert Excel String time to number <p>My excel spreadsheet that I am reading into matlab with xlsread has text for the time in the format of 11:23:23 AM for example. this is a string with no date associated with it so when I try and run datenum or datevec I get an error Failed to lookup month of year. I also tried str2double but that just gives me a series of NaN . What am I looking to do? I need to convert a series of times in an array and then compute the elapsed time among other things.</p>matlabuser12/matlabcentral/answers/contributors/5218558-matlabuser12tag:www.mathworks.de,2005:Question/1602482014-10-27T12:22:18Z2014-10-30T12:02:20ZOpening a txt file with chosen directory location<p>Hi.</p><p>I have a code that works to read values from a formatted txt file that I'm producing with another code. The code works as long as I have the code in the same directory and choose the file using 'uigetfile'. However as I want to eventually run the code on multiple files in a directory, when I set a variable to choose the directory, the code gives this error:</p><pre class="language-matlab">Error using fopen
First input must be a file name of type char, or a file identifier of type double.* *
</pre><p>My x_filename variable comes out as a cell array which I belive is the main issue but having tried to convert and change it, I get different types of errors.</p><p>I know this is probably a very simple fix but I need some assistance to find it.</p><p>My code is something like this:</p><pre class="language-matlab">% Directories for Files
x_Directory = uigetdir;
y_Directory = uigetdir;
</pre><pre class="language-matlab">x_Files = dir([x_Directory, '\*.txt']); % Determine number of files in chosen directory
x_Filename = {x_Files.name}'; % Sanity check
</pre><pre class="language-matlab">file_x = fopen(x_Filename); % open raw txt file
data = textscan(file_x,'%s %s %s %s %s %s %s %s %s %s %s %s %s');
fclose(file_x); % close raw file
celldisp(data);
</pre><pre class="language-matlab">% MAIN CODE HERE
</pre><p>I am testing the above with only one file before I implement the for loop to read multiple files, but the above error is stopping me.</p><p>Can anyone help?</p>Ross/matlabcentral/answers/contributors/4283294-rosstag:www.mathworks.de,2005:Question/1606622014-10-30T07:21:45Z2014-10-30T11:45:10ZI am working on neural networks using matlab 2011<p>The .mat file are the data i have trained. After training the data, the net file is created in the workspace.But, the values,connections,dimensions etc..are not updated in the 'net' file. How do i update the net file?..please help me. I am struggling a lot with this..many thanks.</p>Interest Academics/matlabcentral/answers/contributors/5839149-interest-academicstag:www.mathworks.de,2005:Question/1599832014-10-24T21:15:46Z2014-10-30T11:29:29ZBumblebee 2 image acquisition problem<p>Hi I am trying to capture images with a bumblebee 2 stereo camera, however whenever I attempt to declare a video object, I get the error:</p><pre class="language-matlab">"Error using videoinput (line 379)
winvideo: Image acquisition device is not
accessible.
The parameter is incorrect.
Make sure no other objects or applications
are accessing the same device."
</pre><p>The code I am using to declare the video object is:</p><pre class="language-matlab">vid = videoinput('winvideo', 1, 'RGB24_1024x768')
</pre><p>Also, I am not attempting to access the camera using any other application, therefore I do not understand why it shows that it is inaccessible.</p>Sarisha/matlabcentral/answers/contributors/5548493-sarishatag:www.mathworks.de,2005:Question/1606902014-10-30T11:29:14Z2014-10-30T12:13:09ZHow to brush data automatically from by using meshgrid?<p>I already read the question of igor ( <a href = "http://www.mathworks.com/matlabcentral/answers/8706-bug-a-programming-emulation-of-brush-tool-in-figure-editor">http://www.mathworks.com/matlabcentral/answers/8706-bug-a-programming-emulation-of-brush-tool-in-figure-editor</a> ) and also the answer, but i want to brush data automatically of this function:</p><pre class="language-matlab">[us,P] = meshgrid(0:0.05:2, -2:0.05:2);
Q = sqrt(us.^2*i_max^2-P.^2);
surf(us,P,real(Q),imag(Q), 'Edgecolor','blue');
</pre><p>Can somebody tell me how that works? I just what to "cut out" special parts of that figure. i.e. brush them white, so that they become invisible.</p><p>Thank you for your help.</p>Christian/matlabcentral/answers/contributors/5840007-christiantag:www.mathworks.de,2005:Question/1606892014-10-30T11:26:08Z2014-10-30T11:26:44ZFit function doesn't fit custom arctan function<p>Hi everyone,</p><p>I have come across a rather weird issue, which may be very simple but I cannot figure it out myself. Basically I'm attempting to use the 'fit' function to fit a function to a surface.
The function plots a surface with a rectangular hole using arctan. I define the fittype as below:</p><pre class="language-matlab">myfittype = fittype('(-a*atan(x-b)+a*atan(x-c)).*(-a*atan(y-b)+a*atan(y-c))',...
'independent',{'x', 'y'},'dependent','z')
</pre><p>This also works. Now I'm attempting fitting this to my surface using:</p><pre class="language-matlab">[f, gof] = fit( [x, y], z, myfittype)
</pre><p>This executes but the estimated coefficients (a, b, c) aren't of any use and not even close to the surface.</p><p>Hence, my question: did I misunderstand something? Am I doing something horrible wrong?</p><p>Thanks to everyone who read my post.</p>Moritz/matlabcentral/answers/contributors/3856674-moritztag:www.mathworks.de,2005:Question/1600582014-10-25T14:40:36Z2014-10-30T11:25:40ZHow do you access both camera sensors of the Bumblebee2 camera?<p>Hi</p><p>I am currently using the Bumblebee2 stereo camera with the CMU driver which is compatible with MATLAB's image acquisition toolbox. I am trying to capture two images of a scene using both the right and left cameras of the Bumblebee2, however the image acquisition tool only allows me to access one camera.</p><p>Does anyone know how I can access the other camera?</p>Sarisha/matlabcentral/answers/contributors/5548493-sarishatag:www.mathworks.de,2005:Question/1606872014-10-30T11:10:55Z2014-10-30T11:10:55ZHow to tell Matlab to look for nc files which are stored in a ssh connection ?<p>Hello,</p><p>I am working on Matlab on a Linux system. I want to access from my computer, files that are in the cluster of the university, in a ssh connection. I would like to give the path of my files directly in Matlab, for example like: cd data/temperature/ (path which is under my ssh connection).
Is there something that could do something like: cd ssh -X user@cluster data/temperature/ ?</p><p>Help would be highly appreciated.
Alice</p>Alice/matlabcentral/answers/contributors/5839910-alicetag:www.mathworks.de,2005:Question/1606652014-10-30T08:01:26Z2014-10-30T11:00:36ZQuestion to MATLAB profiler and speed of code<p>Hello dear MATLAB community,</p><p>I have a question concerning this piece of code</p><img src = "/matlabcentral/answers/uploaded_files/20201/Speed%20up.png"><p>This will calculate a piecewise cubic spline for my parametrized function. It is calles so often because it´s inside an optimization routine (fmincon).
My first question is: Is there a way to speed up this code?
And the second question: Why is the runtime of line 11 and 13 and 12 and 14 so different? Both lines are doing the same operation but the the calculation time differs around 30%?</p><p>Thanks for your help,</p><p>David</p>David/matlabcentral/answers/contributors/4226882-davidtag:www.mathworks.de,2005:Question/1606762014-10-30T09:18:52Z2014-10-30T10:56:06ZHow to split the data wrt date in 3 dimensions array<p>Hi all,
I have data starts from 1/Jan/1979 to 31/Dec/2019 year with 3 dimensions array is 10x10x14975. I also have the 3 periods = [1979 1979 ; 1980 1999 ; 2000 2019]. So I want to split the data only with respect to period 2 and 3, then to simulate the mean for that each period.
Please help me. Thanks you.</p>Nam/matlabcentral/answers/contributors/4196912-namtag:www.mathworks.de,2005:Question/1599052014-10-24T08:32:55Z2014-10-30T10:32:09ZHow to assign a string with extenssion to another string to be opened?<p>Let me see if I can explain myself:
I want to open any type of .txt in my SCRIPT.
For this, I demand the name of the .txt to be opened, I save it onto another known for me string, and try to open it.
I am trying it with this code, but I am not able to do it:</p><pre class="language-matlab">fid = input ('Enter the name of the document with the extension: ', 's');
docu = fopen('fid');
if docu == -1
disp('File open not successful');
else
disp('File open successful');
end
mat = fscanf('docu', '%f %f', [2 inf]);
</pre><p>It always displays docu == -1 and some errors regarding fscanf.
I am not yet an expert with Matlab so I would really apreciate some help.
Thank you very much,
Juan</p>juan/matlabcentral/answers/contributors/5787914-juantag:www.mathworks.de,2005:Question/1606862014-10-30T10:29:45Z2014-10-30T10:29:45ZHow to get actual waiting time in a queue rather than mean value ?<p>Hi,
I try to use simevents to simulate customers in a queue.
Is it possible to trace each customer and get individual arrival, waiting and departure times ?
Thanks.</p>Dan/matlabcentral/answers/contributors/21634-dantag:www.mathworks.de,2005:Question/1582442014-10-11T10:03:15Z2014-10-30T10:28:03Zconverting a minute chart<p>Hi guys, i have a table with 6 columns and 4 million rows. Column1 shows the date and column 2 the time. Column 3 the opening price, column4 the max price, column5 the min price and column6 the closing price. The whole table presents a one minute chart. I want to convert this to a two minute chart in the following manner: two rows have to be combined(row1 and row2). Column
1,2,3 should have the values of row1. Column4 should contain the max value of row1 and row2. Column 5 should have the min value of row1 and row2. Column6 should have theclosing value of row2.</p>AA/matlabcentral/answers/contributors/5703029-aatag:www.mathworks.de,2005:Question/1606852014-10-30T10:15:41Z2014-10-30T10:15:41ZRemoving undesired values of a matrix (filtering)<p>Hi,</p><p>I have such a graph.</p><img src = "/matlabcentral/answers/uploaded_files/20213/Untitled.png"><p>I want to remove undesired values to get like a following graph.</p><p>How can I do that?</p><img src = "/matlabcentral/answers/uploaded_files/20214/6.bmp">samet subasi/matlabcentral/answers/contributors/5839720-samet-subasitag:www.mathworks.de,2005:Question/1605312014-10-29T08:55:33Z2014-10-30T10:08:50Zhot to remove block error, (variable transport relay)<p>Making minor project on SIMULATION OF EXTRA HIGH VOLTAGE LONG TRANSMISSION LINE, aftre making this model, find the block error, (variable transport relay) error... anyone plzz guide me</p><p>in the pics, the model, madebyme model and error presents</p><p>images are on zip file, three images are zipped</p>Gaurav Dubey/matlabcentral/answers/contributors/5834863-gaurav-dubey