https://it.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2017-03-30T18:34:40Ztag:it.mathworks.com,2005:Question/3328262017-03-30T17:59:44Z2017-03-30T18:34:40ZUnexpected MATLAB expression?<p>I am attempting to use the strsplit function in MATLAB 2016, but I keep getting an error when running the code.</p><pre class="language-matlab">text = 'Enter the string as an input:';
</pre><pre class="language-matlab">myInput = strsplit(input(prompt));
</pre><p>MATLAB is telling me that there is an issue with the second line.</p>Michael Stewarthttps://it.mathworks.com/matlabcentral/profile/authors/9604501-michael-stewarttag:it.mathworks.com,2005:Question/3328292017-03-30T18:34:38Z2017-03-30T18:34:38Zexport final point of Simulink signal to Workspace ?<p>I have a signal which is changing over the time of simulation, the signal is time variant signal, the final value of this signal which I interested in.
How can I transfer the final point of this signal to Workspace?</p>Khaled Abojlalahttps://it.mathworks.com/matlabcentral/profile/authors/5990958-khaled-abojlalatag:it.mathworks.com,2005:Question/2636642016-01-13T16:54:42Z2017-03-30T18:33:04ZGUIDE UI object positions change between retina display and windows<p>I found a strange behavior for guide making GUIs. I routinely go between my retina display Mac and my home Windows 7 computer (non-retina display) using MATLAB2015b. Even after setting the main figure property and all UI objects to 'normalized' units, when opening and editing a GUI with guide on a Mac with a retina display, all the buttons and UI locations which I edit and add to the GUI appear in the proper location on a Mac Retina display however when opening the same GUI in windows, the buttons are not on the GUI but I think are scaled in position off the GUI perhaps their normalized positions are multiplied some dpi factor which is much higher on retina display, however this factor is not shut off when rendering the edited GUI on a Windows machine. Does anybody else see this behavior or have a solution for it? Thanks,
Linus</p>Linerhttps://it.mathworks.com/matlabcentral/profile/authors/3227793-linertag:it.mathworks.com,2005:Question/3311582017-03-21T22:38:21Z2017-03-30T18:32:29ZGUI Button Groups and Panel Containers Cause Cross Platform Issues?<p>I'm designing multiple GUIs that I would like to be usable on both my Mac (MacBook Pro Retina 15inch early 2013) and on a lab computer running Windows 7. Both have Matlab 2015b. I have reviewed the Matlab documentation titled "Design Cross-Platform UIs in GUIDE", but have still had difficulties.</p><p>I made two GUIs first on my Mac, as it's my main work computer. Below are photos of the original designs when viewed on my Mac.</p><img src = "/matlabcentral/answers/uploaded_files/72969/Original_ANNTrainingGUI_MacView.jpg"><img src = "/matlabcentral/answers/uploaded_files/72970/Original_DOFOptions_MacView.jpg"><p>When viewing the GUIs on the Windows computer, I instead saw the following.</p><img src = "/matlabcentral/answers/uploaded_files/72972/Original_ANNTrainingGUI_WindowsView.JPG"><img src = "/matlabcentral/answers/uploaded_files/72974/Original_DOFOptions_WindowsView.JPG"><p>Playing around with Non-Resizable vs Proportional made no difference. And as changing all the fonts/fontsizes simultaneously seems to make GUIDE hang indefinitely, I decided to edit the GUI on the Windows computer. I did this because the Windows computer is much faster and so I'd much rather the GUI be optimized to this computer anyways. I was hoping my edits would translate back to my Mac with a slightly too large GUI which I could simply set to Proportional. After all, the major problems simply seemed to be that the text was larger when viewed in Windows.</p><p>And so I edited my GUIs through GUIDE on the windows computer, until I had the following (when viewed on the Windows computer):</p><img src = "/matlabcentral/answers/uploaded_files/72975/WindowsEdited_ANNTrainingGUI_WindowsView.JPG"><img src = "/matlabcentral/answers/uploaded_files/72976/WindowsEdited_DOFOptions_WindowsView.JPG"><p>I was happy with them, but I found the first GUI transformed into a monstrosity when viewed on my Mac:</p><img src = "/matlabcentral/answers/uploaded_files/72977/WindowsEdited_ANNTrainingGUI_MacView.jpg"><img src = "/matlabcentral/answers/uploaded_files/72978/WindowsEdited_DOFOptions_MacView.jpg"><p>Fiddling with Non-Resizable vs Proportional yielded no change. It seems that font size alone is not enough. I think perhaps screen resolution and DPI differences could account for the difference in size, but I am utterly baffled as to the tremendous mess that Panel Containers and Button Groups cause. Seeing how the DOFOptions GUI remained legible, <b>I am inclined to believe that somehow the Panels and Groups are treated differently across platforms. Is there some solution to this issue?</b></p>Hendrik Dewaldhttps://it.mathworks.com/matlabcentral/profile/authors/5453382-hendrik-dewaldtag:it.mathworks.com,2005:Question/3322392017-03-28T02:50:56Z2017-03-30T18:29:12ZFinding the optimal minimum of two vectors<p>I have two vectors (97x1) where each element is a standard deviation of a range of data from a larger vector (145x1). I want to find where the optimal solution is to minimize both standard deviations (so not the absolute minimum of each vector individually). I tried looking at some of the optimization tools but couldn't figure out how to apply them to this problem... Any help would be appreciated but please be specific since I am not an experienced programmer.</p>Aaron Morrisonhttps://it.mathworks.com/matlabcentral/profile/authors/9557756-aaron-morrisontag:it.mathworks.com,2005:Question/3313332017-03-22T16:47:19Z2017-03-30T18:25:24ZReal-time heart rate calculation<p>I have a real-time(phonocardiograph) plot which displays data from an electronic stethoscope via the COM port. I am trying to calculate the heart rate but having little success. I have created a <i>uicontrol</i> on the figure to display the BPM and have included the formulas to count the peak signals(beat_count). At the momement 'BPM:' displays on the plot figure but without a value so I am unable to get any BPM_avg reading.</p><pre> a = arduino('COM4','Due');
y=0;
hPlot = plot(NaN);
intervalSize = 200;
currentInterval = 200;
t = 1; % number of samples
atInterval = 1;
beat_count = 0;</pre><pre> quitbutton = uicontrol('style','pushbutton',...
'string','Quit', ...
'fontsize',12, ...
'position',[10,2,50,20], ...
'callback','quitit=1;close');
quitit = 0;
bpmtext = uicontrol('style', 'text',...
'string', ['BPM: '],...
'fontsize', 12,...
'position', [80, 2, 100, 20]);</pre><pre> while(1)
k = 1;
while(t<currentInterval)
b=readVoltage(a, 'A0');
y=[y,b];
if ishandle(hPlot)
set(hPlot, 'YData', y);
else
break; % break out of the loop
end
xlabel('Samples')
ylabel('Voltage')
title('Phonocardiogram')
axis([currentInterval - intervalSize,currentInterval,0,3]);
%grid
t=t+k;
pause(0.002)
end
for m = 2 : length(b)-1
if(b(m) > b(m-1) & b(m) > b(m+1) & b(m) > 2.4)
%disp('Prominant peak found');
beat_count = beat_count + 1;
set(bpmtext, 'string', ['BPM: ',...
num2str(BPM_avg,4)]);
end
end
currentInterval = currentInterval + intervalSize;
atInterval = atInterval + 1;
if ~ishandle(hPlot)
break;
end
fs = 500;
N = length(b);
duration_in_seconds = N/fs;
duration_in_minutes = duration_in_seconds/60;
BPM_avg = beat_count/duration_in_minutes;</pre><pre> end </pre>bilal malikhttps://it.mathworks.com/matlabcentral/profile/authors/4821130-bilal-maliktag:it.mathworks.com,2005:Question/3322812017-03-28T09:09:01Z2017-03-30T18:25:09ZPlotting frequency spectrum of a signal<p>Hi, I wrote this code to obtain plot of frequency spectrum of my signals:</p><pre class="language-matlab">clc; clear all; close all;
</pre><pre class="language-matlab">%% Reading & plotting normal.wav file
normal = audioread('normal.wav');
figure(1)
plot(normal);
xlabel('Number of data','fontsize',12,'fontweight','b');
ylabel('Amplitude','fontsize',12,'fontweight','b');
title('Normal Heart Sound Signal','fontsize',14,'fontweight','b');
</pre><pre class="language-matlab">%% Reading & plotting murmur.wav file
murmur = audioread('murmur.wav');
figure(2)
plot(murmur);
xlabel('Number of data','fontsize',12,'fontweight','b');
ylabel('Amplitude','fontsize',12,'fontweight','b');
title('Murmur Heart Sound Signal','fontsize',14,'fontweight','b');
</pre><pre class="language-matlab">%% Fourier transform
fft_nor = fft(normal);
fft_mur = fft(murmur);
</pre><pre class="language-matlab">%% Calculating fs
% fs_normal
t_nor = 6; % s
N_nor = length(normal);
fs_nor = N_nor / t_nor; % Hz
% fs_murmur
t_mur = 8; % s
N_mur = length(murmur);
fs_mur = N_mur / t_mur; % Hz
</pre><pre class="language-matlab">%% Calculate the frequency axis
f_nor = fs_nor / 2 * linspace(-1,1,fs_nor);
f_mur = fs_mur / 2 * linspace(-1,1,fs_mur);
</pre><pre class="language-matlab">%% Plotting frequency spectrum
% Normal sound
figure(3)
plot(f_nor, abs(fft_nor));
xlabel('Frequency (Hz)','fontsize',12,'fontweight','b');
ylabel('Magnitude','fontsize',12,'fontweight','b');
title('Magnitude FFT Of Normal Signal','fontsize',14,'fontweight','b');
% Murmur sound
figure(4)
plot(f_mur, abs(fft_mur));
xlabel('Frequency (Hz)','fontsize',12,'fontweight','b');
ylabel('Magnitude','fontsize',12,'fontweight','b');
title('Magnitude FFT Of Murmur Signal','fontsize',14,'fontweight','b');
</pre><p>but after running it I have this error:</p><p>Error using plot
Vectors must be the same lengths.</p><p>Error in Q5b (line 40)
plot(f_nor, abs(fft_nor));</p><p>would anyone help me to fix it?</p>Ghazal Hnrhttps://it.mathworks.com/matlabcentral/profile/authors/9800962-ghazal-hnrtag:it.mathworks.com,2005:Question/3326172017-03-29T19:56:24Z2017-03-30T18:23:37Zproblem with detrending data <p>Hi, I wrote the code below to remove trends :</p><pre class="language-matlab">%% Removing trends without using detrend code
t = length(pass);
y = pass;
[r m b] = regression(t,y);
for t_pass = 1:t
y_pass(t_pass) = m * t_pass;
res(t_pass) = pass(t_pass) - y_pass(t_pass);
end
figure(3)
plot(y_pass)
</pre><p>but it isn't correct and I get wrong answer.
would anyone help to how I should change this code to detrend my data?</p>Ghazal Hnrhttps://it.mathworks.com/matlabcentral/profile/authors/9800962-ghazal-hnrtag:it.mathworks.com,2005:Question/3328012017-03-30T15:44:02Z2017-03-30T18:22:01ZObtain every possible combination in array<p>I have 3, 100 x 1 vectors that I am combining to make a m x 4 matrix. To obtain 4 columns in the desired output, two elements from the first vector are selected as the first two elements in a row, and then one element from the second vector as the third element, and one element from the third vector as the fourth element to complete the m x 4. I would like to get every possible row combination possible in one large matrix. I started with a huge nested for loop and quickly got lost and assume there must be a better way. Any help is appreciated.</p>Tyler Murrayhttps://it.mathworks.com/matlabcentral/profile/authors/8637352-tyler-murraytag:it.mathworks.com,2005:Question/2753582016-03-25T02:02:14Z2017-03-30T18:18:17ZHow to determine phase of a sine wave using FFT<p>Dear MATLAB experts,</p><p>For a small project that I want to do, I need to compute the phase of a sine wave. However, I was unable to obtain a correct result. I have posted my code with this message (please see attachment) for your review and comments. If anyone could help me with this, I would greatly appreciate it.</p><p>Thank you!</p><p>Fuh</p>Fuh-Chernghttps://it.mathworks.com/matlabcentral/profile/authors/1057491-fuh-cherngtag:it.mathworks.com,2005:Question/3328242017-03-30T17:36:45Z2017-03-30T18:12:58ZHow to transform an array from n x m into nm x 1?<p>Hello,</p><p>I am quite new and fresh on matlab, had a couple weeks of trial and error with it... Anyways, I have this little problem thats in the way between struggle and finished coursework.</p><p>PROBLEM.</p><p>Lets say i have a matrix,</p><pre class="language-matlab">A = [1,2,3; 4,5,6; 7,8,9] % dimensions 3x3
</pre><p>DESIRED SOLUTION.
Is there an easy way to turn it into:</p><pre class="language-matlab">B = [1;2;3;4;5;6;7;8;9] % dimensions 9x1
</pre><p>THANK YOU a lot in advance :)</p>Gediminas Sadaunykashttps://it.mathworks.com/matlabcentral/profile/authors/9760667-gediminas-sadaunykastag:it.mathworks.com,2005:Question/3328022017-03-30T15:44:44Z2017-03-30T18:08:14ZHow i can extract feature point using "extractFeatures" function?<p>Hello there,
I am trying to use the computer vision toolbox, to detect some object surface.
this is a snapshot of my code, i used the code that shared on the documentation of the toolbox.
but i have an error with extractFeatures function.
when i searched throw the description i find that it works with binary images; is that right?
-------------</p><img src = "/matlabcentral/answers/uploaded_files/73852/Capture.PNG">Sanaa Asalhttps://it.mathworks.com/matlabcentral/profile/authors/10044748-sanaa-asaltag:it.mathworks.com,2005:Question/3328282017-03-30T18:05:07Z2017-03-30T18:05:07ZI keep getting an error when trying to run the following command from the MATLAB Fundamentals class (pg 6-11 in course notes). Doesn't writetable overwrite a file if it already exists?<p>writetable(standings,'EPLstandings.xlsx')</p><p>Error using writetable (line 121)
Unable to save the workbook to file 'C:\EPLstandings.xlsx'. Check that write permissions are available, there is sufficient disk space, and the file can be written to or created.</p>John Reesehttps://it.mathworks.com/matlabcentral/profile/authors/9000178-john-reesetag:it.mathworks.com,2005:Question/3328272017-03-30T18:04:09Z2017-03-30T18:04:09ZWhy does my MacBook pro outperform a 16core, 64gb VM instance of Matlab?<p>I was recently given an opportunity to run a custom function I wrote that does a lot of matching between multiple files on a 16 core/ 64gb ram VM with an instance of Matlab 2016b running. On my MacBook Pro, it takes 9 seconds to complete one pass of matching on my laptop. It takes 21 seconds on the VM.</p><p>Can anyone provide insight into what might be causing the speed difference. I was hoping to run this function on the VM to speed up processing several million records.</p>Isabellahttps://it.mathworks.com/matlabcentral/profile/authors/2286559-isabellatag:it.mathworks.com,2005:Question/3303612017-03-17T08:23:32Z2017-03-30T18:03:34ZStartup configuration problems after installing R2017a parallel to R2012a<p>Hi,</p><p>til yesterday I'ved used only Matlab R2012a on my machine. Everything was fine and working well - however, due to the usage of some functions, which were not available under R2012a, I had to install R2017a yesterday. The installation itself worked smoothly. But after the startup of R2017a I'm getting a lot of warnings and errors in the command window. Typical warnings are:</p><pre class="language-matlab">Warning: Name is nonexistent or not a directory:
C:\Users\wallscheid\Documents\MATLABC:\Program
Files\MATLAB\R2017a\resources\opti
Warning: Name is nonexistent or not a directory: C:\Program
Files\MATLAB\R2017a\resources\opti\examples
Warning: Name is nonexistent or not a directory: C:\Program
Files\MATLAB\R2017a\resources\opti\help
Warning: Name is nonexistent or not a directory: C:\Program
Files\MATLAB\R2017a\resources\opti\help\opti_html
Warning: Name is nonexistent or not a directory: C:\Program
Files\MATLAB\R2017a\resources\opti\solvers
Warning: Name is nonexistent or not a directory: C:\Program
Files\MATLAB\R2017a\resources\opti\solvers\mosek
Warning: Name is nonexistent or not a directory: C:\Program
Files\MATLAB\R2017a\resources\opti\solvers\mosek\utilities
...
</pre><p>Also, I'm getting the follow errors messages during startup:</p><pre class="language-matlab">Undefined function or variable 'rmiml.getAll'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'rmiml.visibleInToolstrip'.
Undefined function or variable 'matlab.internal.environment.context.isMATLABOnline'.
</pre><p>During my work with R2012a I've installed some open-source toolboxes, such as IPOPT (https://projects.coin-or.org/Ipopt). Some of these toolboxes configured Matlab automatically to link theirselves with Matlab, so I'm not sure what exactly had been changed in the startup routine. I somehow assumed that a new Matlab installation will have its completly own startup routine, but that seems to not be the case.</p><p>As I'm not a "Matlab Pro", I would be very grateful for receiving adivce how to fix that startup problem under R2017a.</p><p>Kind regards,
walli</p>wallihttps://it.mathworks.com/matlabcentral/profile/authors/7789450-wallitag:it.mathworks.com,2005:Question/989432009-06-27T01:11:00Z2017-03-30T18:02:59ZHow can I use the NULL file in MATLAB 7.3 (R2006b)?<p>I would like to use the NULL file from MATLAB to suppress output to the screen. In earlier releases of MATLAB I would use the file identifier of 0 for this purpose.</p>MathWorks Support Teamhttps://it.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:it.mathworks.com,2005:Question/3328122017-03-30T16:56:02Z2017-03-30T17:54:04ZHow to save numerical array as file (any format) with different precisions (format) for different columns in the same array?<p>Hi
I am matlab 2016b user.
I have one numerical array (950*2 double).
When I save this, I want to save 1st column with integer format (no decimal point...I mean %.0f)
and to save 2nd column with scientific notation with 16 sigifinicant digits....such as '4.123456789012345e-11'.
This is important issue with processing speed in my code. So far, when I use .mat format (binary) with
save' function, it gave 9 kb in file size. However, I may need to use no-binary format like...txt....csv...etc.
When I tried fprintf and dlmwrite functions with diverse options, 26 kb was record with txt/csv format.
I also saw some similar answers using loop for fprintf function, but regarding code running time issue, I hope I can hear another answer using for loop.</p><p>Do you know how to do it?</p>Deohttps://it.mathworks.com/matlabcentral/profile/authors/8363057-deotag:it.mathworks.com,2005:Question/3324922017-03-29T09:02:27Z2017-03-30T17:50:39Zhow to implement knn classification?<p>we are working on a power system on which we have to determine whether the failure of the power system is a fault or not a fault. We have created a dataset with all possibilities of faults and not faults of the system called training set. we have created another excel sheet called the training set in which we have taken some values of faults and not faults from the dataset. We want to use knn algorithm and euclidean distance to compare/classify whether the readings in the training set are the values of faults or not faults when compared with the original dataset. As we are putting four five values in the training set, how do we make matlab read and classify all the values one after the other without manually entering the values</p><p>P.S- 1 represents 'fault' and 2 represents 'not a fault'</p>Nana Fernandeshttps://it.mathworks.com/matlabcentral/profile/authors/10002966-nana-fernandestag:it.mathworks.com,2005:Question/3328182017-03-30T17:19:58Z2017-03-30T17:40:15ZI have a vector with M elements. And I want to divide it into parts, with "n" elements each. How do I do that?<p>I have a vector with M elements. And I want to divide it into parts, with "n" elements each. How do I do that?</p>Ana Vasconcelloshttps://it.mathworks.com/matlabcentral/profile/authors/9791059-ana-vasconcellostag:it.mathworks.com,2005:Question/3328212017-03-30T17:28:39Z2017-03-30T17:37:36ZCompute the corresponding height h <p>A water tank consists of a cylindrical part of radius r and height h and a hemispherical top. The tank is to be constructed to hold 600 m3 when filled. The surface area of the cylindrical part is 2πrh and its volume is πr2h. The surface area of the hemispherical top is given by 2 πr2 and its volume is given by 2πr3/3. The cost to construct the cylindrical part is Rs. 4000 per square meter of surface area; the hemispherical part costs Rs. 6000 per square meter. Use the fminbnd function to compute the radius that results in the least cost. Compute the corresponding height h.</p>Ashish Shrivastavahttps://it.mathworks.com/matlabcentral/profile/authors/10054805-ashish-shrivastavatag:it.mathworks.com,2005:Question/3328252017-03-30T17:36:58Z2017-03-30T17:36:58ZIs it possible to manage MatLab and Simulink remotedly?<p>Hi everyone,
I am a student and I want to know if MatLab or Simulink have any toolbox to make laboratory experience online. The aim of this project is to offer other students like me the chance to study Control subjects at their houses or wherever they want by letting them measuring data and programming controllers online. I have read about the toolbox MatLab Web Server and I think it is no longer available. So I am a bit lost right now.
Are there any other toolbox I can use?
Thanks for the help.
Diego</p>Diego Rodríguezhttps://it.mathworks.com/matlabcentral/profile/authors/7572662-diego-rodrigueztag:it.mathworks.com,2005:Question/3328232017-03-30T17:34:36Z2017-03-30T17:34:36ZODBC problems at writing data in the Mysql database on windows 10<p>Hi,</p><p>I'm using ODBC MySQL on windows 10 to insert a matlab table variable containing 17000 rows in a MySQL database table using the datainsert() function. I made all the insertions at once. However I'm having the following error and I can't figure out what is wrong (the column type of the column 'idCountry' is ok between the table variable on matlab and the field on the database. Any help or insight will be really appreciated:</p><pre class="language-matlab">java.sql.SQLException: SQL Exception : Unknown SQL Type for PreparedStatement.setObject (SQL Type=-9
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setObject(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setObject(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.emulateExecuteBatch(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeBatchUpdate(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeBatch(Unknown Source)
at com.mathworks.toolbox.database.writeTheData.cellWrite(writeTheData.java:284)
Error using database.jdbc.connection/datainsert (line 301)
Unable to complete insert operation. [MySQL][ODBC 5.3(w) Driver][mysqld-5.7.15-log]Out of range value for column 'idCountry' at row 1|
</pre><p>Thanks,</p><p>Carlos</p>Carlos Perezhttps://it.mathworks.com/matlabcentral/profile/authors/984446-carlos-pereztag:it.mathworks.com,2005:Question/3327602017-03-30T04:00:00Z2017-03-30T17:34:04ZWhy do I see a prompt to "Allow incoming connections" each time I open MATLAB R2017a?<p>Why do I see a prompt to "Allow incoming connections" each time I open MATLAB R2017a? Even after I choose "Allow", this message still appears every time I open up MATLAB. My firewall is enabled on my computer but I have an exception setup for "MATLAB R2017a".</p>MathWorks Support Teamhttps://it.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:it.mathworks.com,2005:Question/3328222017-03-30T17:32:01Z2017-03-30T17:32:01ZK-Means Clustering Help for Three Clusters<p>Hello MATLAB Community.
I have a matrix of 30x59, containing Feature Vectors of 30 Images.I want to plot Three clusters/Centres but it is showing an error.
"DATA MUST BE A SINGLE MATRIX Y OR PAIR OF MATRIX X,Y"
on the other hand when I draw 2 clusters/Centres it works perfectly.
Kindly help me.</p>Shahid Hussainhttps://it.mathworks.com/matlabcentral/profile/authors/9641719-shahid-hussaintag:it.mathworks.com,2005:Question/3327952017-03-30T15:15:40Z2017-03-30T17:29:51Zhow can i change the place where files are being saved?<p>i have a matlab program running python script. the script creates files and i want the ability to tell matlab where i want the files to be saved. right now all the files are saved on my working directory.</p>ofhttps://it.mathworks.com/matlabcentral/profile/authors/6498356-oftag:it.mathworks.com,2005:Question/3322822017-03-28T09:09:04Z2017-03-30T17:29:04ZHow to import multiple .nc files of different lengths<p>Hello,</p><p>I'm trying to import 164 3-D files of size 192x94x365(6).
The files contain gridded climate data and are stored annually.</p><p>I'm struggling to import these into a single, large, 4-D file due to the extended length of the leap year files.
Matlab returns a dimension mismatch.</p><p>I have this:</p><pre class="language-matlab">year=[1851:2014];
for ii=1:164
clear fnpath0 fname0 fname1;
fnpath0 = 'myfilepath';
fname0 = sprintf('uwnd.10m.%d.nc',year(ii));
fname1 = [fnpath0 fname0];
Uwndorg = ncread(fname1,'uwnd');
Uwndall(22:60,30:59,:,ii)=Uwndorg(22:60,30:59,:);
end
</pre>Gemmahttps://it.mathworks.com/matlabcentral/profile/authors/8017960-gemmatag:it.mathworks.com,2005:Question/3328162017-03-30T17:10:02Z2017-03-30T17:27:08ZTrouble with compiler for MATCONT<p>I am using Matlab2016a on Mac 10.12 Sierra. I am trying to use MATCONT which is a package for bifurcation diagrams in Matlab. I downloaded that. I typed on the command line 'mex -setup' and it gave me an error:
Error using mex
No supported compiler or SDK was found. For options, visit <a href = "http://www.mathworks.com/support/compilers/R2016a/maci64.html">http://www.mathworks.com/support/compilers/R2016a/maci64.html</a>.</p><p>I downloaded and installed XCode Version 8.3 (8E162). But it is still giving me the same error. I am not sure what's going on. Any timely help would be greatly appreciated.</p>Rosehttps://it.mathworks.com/matlabcentral/profile/authors/2816791-rosetag:it.mathworks.com,2005:Question/3328202017-03-30T17:23:27Z2017-03-30T17:23:27Zusing monte carlo analysis for construction risks<p>i need matlab codes where i can enter multiple cost variables and items so it could do multiple iterations/simulations to generate random number for each iteration</p>omar elbardissyhttps://it.mathworks.com/matlabcentral/profile/authors/10054526-omar-elbardissytag:it.mathworks.com,2005:Question/3328192017-03-30T17:20:16Z2017-03-30T17:20:16ZHow to create a histogram with two y axis scales<p>Does anyone know a way to create a histogram of two sets of data, each with a different y axis? My x_data has much less counts than my y_data and so I would like to have two y (counts) axes, one to the right and one to the left, similar to what yydata does, but for histograms.
My code showing how to plot two sets of data on a histogram is below - but this only provides one y axis.</p><pre class="language-matlab">figure;
h1=histogram(x_data);
set(h1,'FaceColor',[0.8500 0.3250 0.0980],'BinWidth',5);
hold on;
h2=histogram(y_data);
set(h2,'FaceColor',[0 0.4470 0.7410],'BinWidth',5);
ylabel('counts');
xlabel('Period (minutes)');
legend('xData','yData');
alpha(0.5); %transparency
</pre>Sharon Rourkehttps://it.mathworks.com/matlabcentral/profile/authors/8784571-sharon-rourketag:it.mathworks.com,2005:Question/3328172017-03-30T17:11:08Z2017-03-30T17:11:08ZPolyspace Code Prover (R2014b) - Float32 Overflow due to static local variables<p>Hello,</p><p>I have the following code function.
When I check the code with Polyspace Code Prover (R2014b), I get an "orange" Overflow in the formula (*1) due to the static local variable "X_Sa2_LPF_UnitDelay" that is assumed with the full float32 range (-3.4029E+38 .. 3.4029E+38). But by the algorithem (low-pass-filter) the variable value can not larger as the Value of input "Sa1_InRaw". The Input "Sa1_InRaw" is limited by DRS to +/-50. "Sa1_Constant" is a constant with a also fixed range.</p><p>Can I limit static local variables in the configuration? Can I avoid this overflow by any other option?</p><pre class="language-matlab">float Sa1_InRaw;
float Sa1_OutFilt;
</pre><pre class="language-matlab">const float Sa1_Constant = 0.3F;
</pre><pre class="language-matlab">void Sa3_LPF1(void) {
</pre><pre class="language-matlab">float Sa2_LPF_Add;
static float X_Sa2_LPF_UnitDelay = 0.F;
</pre><pre class="language-matlab">Sa2_LPF_Add = ((Sa1_InRaw - X_Sa2_LPF_UnitDelay) * Sa1_Constant) + X_Sa2_LPF_UnitDelay; //(*1)
X_Sa2_LPF_UnitDelay = Sa2_LPF_Add;
</pre><pre class="language-matlab">Sa1_OutFilt = Sa2_LPF_Add;
}
</pre><p>Thanks in advance!
Best Regards,
Thomas</p>Thomas Katemannhttps://it.mathworks.com/matlabcentral/profile/authors/9938722-thomas-katemanntag:it.mathworks.com,2005:Question/3328132017-03-30T16:57:46Z2017-03-30T17:10:37ZMatlab plots only one point<p>I want to plot the function Y = X^m/(5^m + X^m) on a Y vs. X graph for different values of m, and I used the code below but MATLAB plots only one point. Can someone help me?</p><pre class="language-matlab">for m = 1:10
X = linspace(1, 100, 1001);
Y = (X.^m) / (5^m + X.^m);
plot(X, Y);
end
</pre><p>Thanks!</p>positron96https://it.mathworks.com/matlabcentral/profile/authors/4590643-positron96tag:it.mathworks.com,2005:Question/2625712016-01-04T11:38:09Z2017-03-30T17:07:30ZI Want Matlab code to cut ROI From the folowing medical image <p>I Want Matlab code to cut ROI From the folowing medical image</p>haithem abdelghanyhttps://it.mathworks.com/matlabcentral/profile/authors/6195722-haithem-abdelghanytag:it.mathworks.com,2005:Question/2167082015-05-14T17:26:47Z2017-03-30T17:04:00ZConvert image into Patches of size 64*64 and get each patch<p>Hello, I have RGB image dataset.I want to convert an image into patches and save each patch.How to do this in matlab. The patch size should be 64*64</p>Tahirhttps://it.mathworks.com/matlabcentral/profile/authors/5199390-tahirtag:it.mathworks.com,2005:Question/3328072017-03-30T16:10:10Z2017-03-30T17:04:16Zsir i m getting error like this"Undefined function or variable 'kpl'."<p>sir i have run this code but it showing some error like undefined function. can u please help me to rectify this error.</p><pre class="language-matlab">Na=8;
Nr=8;
e=25;
% comparing interest points initialisation
ccmprh=zeros(size(kpl,1)-1,1);
ccmprw=zeros(size(kpl,1)-1,1);
lenkp=length(kp); % length of kp for 'for loop'
lencmp=length(ccmprh);
</pre>vani shreehttps://it.mathworks.com/matlabcentral/profile/authors/9540780-vani-shreetag:it.mathworks.com,2005:Question/3328152017-03-30T17:02:57Z2017-03-30T17:04:33Zhow to set up matlab and postgresql 9.6.2?<p>I saw you can use the ODBC driver to connect matlab with PostgreSQL 9.2 ( <a href = "https://www.mathworks.com/help/database/ug/postgresql-odbc-windows.html">as you can read here</a> ) . But there is a way to connect matlab with the lastest realease 9.6.2 ?</p>rafael ospinahttps://it.mathworks.com/matlabcentral/profile/authors/9411932-rafael-ospinatag:it.mathworks.com,2005:Question/3328142017-03-30T17:01:57Z2017-03-30T17:01:57ZR2017a arduino_gettingstarted compilation error<p>I have followed the getting started instructions but get this compiler error:
C:/ProgramData/MATLAB/SupportPackages/R2017a/toolbox/target/supportpackages/arduinotarget/registry/../src/MW_ArduinoHWInit.cpp:33:43: error: 'Serial_begin' was not declared in this scope
Serial_begin(0, <i>RTT_BAUDRATE_SERIAL0</i>);
^
gmake: <b>*</b> [MW_ArduinoHWInit.o] Error 1
### Build procedure for model: 'arduino_gettingstarted' aborted due to an error.
I am connected to a Mega 2560 and have configured the model for this.</p><p>The MATLAB and Simulink HW Support Packages are installed and I have installed the MinGW64 compiler:
'MEX configured to use 'MinGW64 Compiler (C)' for C language compilation.'
What am I missing?</p>Justin Mellorhttps://it.mathworks.com/matlabcentral/profile/authors/911324-justin-mellortag:it.mathworks.com,2005:Question/3327892017-03-30T15:00:04Z2017-03-30T17:01:32ZSplittingn and combining the number again <p>If I have '9,36.486' (double or char) and wish to multiple the 36 with (100/60) and the 486 with *1/100. Can I split the '9,36.486', in three parts and multiply the parts and then recombine them ?</p>khaled hassanhttps://it.mathworks.com/matlabcentral/profile/authors/7576498-khaled-hassantag:it.mathworks.com,2005:Question/3327582017-03-30T12:28:10Z2017-03-30T16:59:42ZHow to remove zeros from a 3D array<p>Hi everyone, I have a 3D array like this A(v,n,m) , I need to remove zero columns and and rows from first 2 dimens</p><pre> for m=1:N
A(~any(A,2),:,m)=[];
A(:,~any(A,1),:m)=[];
end</pre><p>I tried this code but I got error. If anyone can help me, appreciated.</p>Burakhttps://it.mathworks.com/matlabcentral/profile/authors/4209819-buraktag:it.mathworks.com,2005:Question/3326832017-03-30T06:01:16Z2017-03-30T16:59:05ZI'm trying to implement an algorithm for prediction of missing nodes using Matlab. But, there are some errors in my coding , Could anyone please correct my code?<pre class="language-matlab">clc;
edges = dlmread('twitnet.csv');
edges(all(edges == 0, 2), :) = [];
[uedges, ~, erow] = unique(edges.', 'stable'); %transpose and stable to give the same output as graph
X = full(sparse(erow(1:2:end), erow(2:2:end), 1, numel(uedges), numel(uedges)));
X = X + X.';
CDcalculation(CD); %consistency degree
* error after this *
</pre><p>Thanks in advance</p>SUNANNA S Shttps://it.mathworks.com/matlabcentral/profile/authors/9869601-sunanna-s-stag:it.mathworks.com,2005:Question/16172011-02-19T07:39:57Z2017-03-30T16:57:48ZPhotovoltaic<p>can anyone forward the simulink model of MPPT used for Photovoltaic</p>Zarinahttps://it.mathworks.com/matlabcentral/profile/authors/2732021-zarinatag:it.mathworks.com,2005:Question/3327992017-03-30T15:31:54Z2017-03-30T16:55:28ZCan you save the function created by curve fitting app into a real function for later use? <p>I know we can export it to workspace, but if I want to be able to use it again later, I know i must save it. I guess there is away to convert that .sfit file to a matlab function?</p>Francois Lachancehttps://it.mathworks.com/matlabcentral/profile/authors/6933702-francois-lachancetag:it.mathworks.com,2005:Question/3326882017-03-30T06:28:49Z2017-03-30T16:52:03ZUnable to create project in xilinx vivado 2015.2 from simulink using hdl workflow adviser,Getting error [12-172],how can get pass this?<p>Hi,</p><p>I am trying to run HDL work flow adviser for the standard LED blink example from MATLAB. I am new to this style of programming FPGA, can someone advice me what to do or where I can find a solution. This is the following error:</p><pre class="language-matlab">Failed
INFO: [Ipptcl 7-578] No Compatible Board Interface found.Board Tab not created
VHDL Output written to : C:/MATLAB Saved files/hdl_prj/vivado_ip_prj/vivado_prj.srcs/sources_1/bd/system_top/hdl/system_top.vhd
VHDL Output written to : C:/MATLAB Saved files/hdl_prj/vivado_ip_prj/vivado_prj.srcs/sources_1/bd/system_top/hdl/system_top_wrapper.vhd
Wrote : <C:/MATLAB Saved files/hdl_prj/vivado_ip_prj/vivado_prj.srcs/sources_1/bd/system_top/system_top.bd>
make_wrapper: Time (s): cpu = 00:00:04 ; elapsed = 00:00:05 . Memory (MB): peak = 390.328 ; gain = 123.043
# regsub -all "system_top.vhd" [get_files system_top.vhd] "system_top_wrapper.vhd" TOPFILEPATH
# add_files -norecurse $TOPFILEPATH
ERROR: [Vivado 12-172] File or Directory 'Saved' does not exist
INFO: [Common 17-206] Exiting Vivado at Thu Mar 30 11:54:46 2017...
</pre><pre class="language-matlab">Elapsed time is 11.1759 seconds.
</pre>Ariz Wakilhttps://it.mathworks.com/matlabcentral/profile/authors/5154303-ariz-wakiltag:it.mathworks.com,2005:Question/3327522017-03-30T11:56:52Z2017-03-30T16:50:50ZN-D matrix accumarray<p>Hi,</p><p>I'm working with (large) N-D matrices and need to sum elements along their dimensions, according to grouping index vectors. To exemplify</p><pre class="language-matlab">A is a 4-D matrix with dimensions (3,4,2,7), and
x1 = (2 1 2 3) <- same length as 2nd dimension in A
x2 = (3 3 2 1 3 2 4) <- same length as 4th dimension in A
</pre><p>I would like to find a formula f to sum the matrix along dimension 2 using the grouping variable x1 and along dimension 4 using the grouping variable x2. In the case of x2, for instance, the first, second and fifth 3x4x2 hyperplanes (group "3") should be summed together, as should the third and sixth (group "2"), while groups "1" and "4" should not change.
Whether through a one-liner or a loop through the two dimensions involved, the final result should be a matrix of dimension (3,3,2,4).</p><p>I've seen similar cases using accumarray and/or arrayfun, but only applied to special (and straightforward) 2-D or 3-D (<- flattened to 2-D in the solutions proposed) matrices.</p><p>Is there a generalized (matrix of any dimension) and efficient way, through those or other functions, to obtain the result above?</p><p>Greateful in advance for any solution or lead you could provide.</p><p>Kind regards</p><p>Dan</p>Daniele Rocchettahttps://it.mathworks.com/matlabcentral/profile/authors/7861802-daniele-rocchettatag:it.mathworks.com,2005:Question/3322472017-03-28T04:22:22Z2017-03-30T16:48:49ZPassing a pointer from Matlab to C<p>I am attempting to pass a matrix from a class in Matlab to a code in C. The code in C cannot be changed and requires a double* to be passed in as an argument. I am trying to use libpointer(...) to modify the matrix into something that can be passed to the C code through a calllib(...) function.</p><p>I cannot post all of the code because it is quite extensive.
The function of the Matlab code reads:</p><pre class="language-matlab">function obj = set.RP(obj, vals)
rho = vals{1};
pres = vals{2};
if strcmp(rho,'None')
rho = obj.R;
end
if strcmp(pres, 'None')
pres = obj.P;
end
disp(rho)
disp(pres)
idxptr = libpointer('doublePtr',[rho, pres]);
disp(idxptr)
calllib('canteraLib', 'thermo_set_RP', obj.thermo, idxptr)
end
</pre><p>The function in the C code reads:</p><pre class="language-matlab">int thermo_set_RP(int n, double* vals)
{
try{
ThermoCabinet::item(n).setState_RP(vals[0], vals[1]);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
}
}
</pre><p>Thank you for your time</p><p>-Emil</p>Emil A Atzhttps://it.mathworks.com/matlabcentral/profile/authors/4567969-emil-a-atztag:it.mathworks.com,2005:Question/3322662017-03-28T07:52:46Z2017-03-30T16:48:27ZPoblems with H05 bluetooth module<p>Hi!</p><p>I'm trying to receive data from a sesnor in an Arduino UNO over H05 module using a dongle in my PC. When I receive data in Putty software there is no problem but when I try to establish the communication using matlab, no data is being received. Any idea of the problem? I've attached the error in Matlab in order to give further details.</p><pre class="language-matlab">Serial Port Object : Serial-COM14
</pre><pre> Communication Settings
Port: COM14
BaudRate: 38400
Terminator: 'CR/LF'</pre><pre> Communication State
Status: open
RecordStatus: off</pre><pre> Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0</pre><pre class="language-matlab">Warning: Unsuccessful read: A timeout occurred before the Terminator was reached..
Subscripted assignment dimension mismatch.
</pre><pre class="language-matlab">Error in Medida_Bluetooth_hcsr04>Medir_Callback (line 104)
handles.distancia(i)=fscanf(s,'%f');
</pre>Itziar Uzquedahttps://it.mathworks.com/matlabcentral/profile/authors/9763198-itziar-uzquedatag:it.mathworks.com,2005:Question/3326892017-03-30T06:30:33Z2017-03-30T16:42:24ZDivide an image along lines and indexing different segments they produces <p>i wanted to plot axes at a specific points but couldn't. so added lines using hline and vline commands. now i have four segments at that point, but since they are not equal i can't use blockproc. but what need is i have got to index the four segments so that i can determine positions with respect to the intersecting points as quadrant position treating that point as origin.And I could also work with drawing normal axes, putting that point at origin and thus dividing the overall image into four indexed quadrants. Any of these two approach will do for me. but sadly i can't seem to do any. I'll be really grateful if anyone could help.Thanks.</p>Tasneem Tabassumhttps://it.mathworks.com/matlabcentral/profile/authors/9128595-tasneem-tabassumtag:it.mathworks.com,2005:Question/3328082017-03-30T16:11:50Z2017-03-30T16:28:09ZI have two n x 1 matrices, How do I combine for ordered pairs but only consider each element once, and all pairs have to be forward-unique (1,2) ~= (2,1) until all elements have be paired<p>I have two n x 1 matrices, How do I combine matrices into a new n x 2 matrix for ordered pairs but only consider each element in the second matrix once, and all pairs have to be forward-unique (1,2) ~= (2,1) until all elements have be paired</p>Brian Connetthttps://it.mathworks.com/matlabcentral/profile/authors/8529570-brian-connetttag:it.mathworks.com,2005:Question/3328102017-03-30T16:26:04Z2017-03-30T16:40:01Zspecific mex compiler matlab linux 64 bit<p>HI everybody,
I am trying to set up a specific compiler for my mexfiles in matlab under debian 64bit. First of all I have tried to run</p><pre class="language-matlab">mex -setup -v
</pre><p>but it does not provide any option as I expected</p><pre class="language-matlab">Verbose mode is on.
... Looking for compiler 'gcc' ...
... Executing command 'which gcc' ...Yes ('/usr/bin/gcc').
... Executing command 'gcc -print-file-name=libstdc++.so' ...Yes ('/usr/lib/gcc/x86_64-linux-gnu/6/libstdc++.so').
Found installed compiler 'gcc'.
... Looking for compiler 'gcc' ...
... Executing command 'which gcc' ...Yes ('/usr/bin/gcc').
... Executing command 'gcc -print-file-name=libstdc++.so' ...Yes ('/usr/lib/gcc/x86_64-linux-gnu/6/libstdc++.so').
Found installed compiler 'gcc'.
MEX configured to use 'gcc' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. You will be required
to update your code to utilize the new API.
You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
</pre><pre class="language-matlab">To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
</pre><p>Then I tried to copy /usr/local/MATLAB/R2017a/bin/mexopts.sh in ~/.matlab/R2017a/mexopts.sh and modify the configurations as in</p><pre> CC='/usr/bin/gcc-4.9'</pre><p>and analogously for g++. However the following output shows that this didn't work, either</p><pre class="language-matlab">>> cc = mex.getCompilerConfigurations('C','Selected')
</pre><pre class="language-matlab">cc =
</pre><pre> CompilerConfiguration with properties:</pre><pre> Name: 'gcc'
Manufacturer: 'GNU'
Language: 'C'
Version: ''
Location: '/usr/bin/gcc'
ShortName: 'gcc'
Priority: 'A'
Details: [1×1 mex.CompilerConfigurationDetails]
LinkerName: ''
LinkerVersion: ''
MexOpt: '/home/anicastro/.matlab/R2017a/mex_C_glnxa64.xml'</pre><p>and /usr/bin/gcc points to gcc 6.3. I tried also by changing the file in /usr/local/MATLAB/R2017a/bin/mexopts.sh but the result is the same.</p><p>I have little experience with mex files, how can I solve this?</p><p>Cheers</p><p>Andrea</p>Andrea Nicastrohttps://it.mathworks.com/matlabcentral/profile/authors/7126295-andrea-nicastrotag:it.mathworks.com,2005:Question/3328092017-03-30T04:00:00Z2017-03-30T16:19:11ZAbout LTE MBSFN<p>I have a question about MBSFN. </p><p>I found this </p><p><<https://www.mathworks.com/help/releases/R2016b/lte/ug/transmission-modes-an> </p><p>d-transmission-schemes.html> shows there is the MBSFN at only TM9,TM10 with </p><p>port7 </p><p>I also found the MBSFN reference signals mapped with port 4.(information </p><p>reference </p><p><<http://www.sharetechnote.com/html/FrameStructure_DL.html#RS_UE_Specific>> ) </p><p>But I didn't see any TxScheme Port4 in this document </p><p><<https://www.mathworks.com/help/releases/R2016b/lte/ref/ltepdsch.html#ltePDS> </p><p>CH.TxScheme> </p><p>How can I get the MBSFN reference signals port 4 with MATLAB. </p>MathWorks Support Teamhttps://it.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:it.mathworks.com,2005:Question/3306942017-03-19T16:36:27Z2017-03-30T16:17:57ZHow to update legend in MatLab R2017a<p>I found that in the new version of MatLab, R2017a, they removed the option of updating the legend (Right-Click on legend ----> select the option Refresh).
So, how one can update the legend in MatLab R2017a?</p>Jamal Ahmadhttps://it.mathworks.com/matlabcentral/profile/authors/3986234-jamal-ahmad