https://de.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2018-12-10T16:36:50Ztag:de.mathworks.com,2005:Question/4349712018-12-10T15:55:57Z2018-12-10T16:36:50ZBar chart colors depending on their value(in MATLAB 2014a)
I would like to plot visuals to verify if a set of data complies with the requirements values.
req = [10,5,3];
data=[9,6,3];
To plot the following bar chart I used:
bar(req,0.5)
newXticklabel = {'label1','label2','label3'};
set(gca,'XtickLabel',newXticklabel);
hold on
bar(data,0.25,'g')
hold off
My question is: how do I change the color of one bar in red if the data is lower than the requirement value ?
Patrick Fhttps://de.mathworks.com/matlabcentral/profile/authors/12647913-patrick-ftag:de.mathworks.com,2005:Question/4349802018-12-10T16:29:26Z2018-12-10T16:36:00ZMake x axis ticks and extent match Hello, I am trying to plot timeseries data. Each data parameter was collected over a different length of time. I have successfully limited each plot to the same data collection range, however the ticks on my fourth subplot are not the same. Can anyone tell me why this is the case and how I might fix it?
This is my code:
close all;
f10 = figure(10);
%Define time to plot (for x axis)
t1 = datenum(2018,07,20,00,00,00);
t2 = datenum(2018,10,05,00,00,00);
subplot(4,1,1);%mfet ph
plot(mfet6.SDN, mfet6.pHint_prelim);
ylabel('mfet6 pH');
datetick;
xlim([t1 t2]);
xticks=get(gca,'xtick');
set(gca,'xticklabel',cellstr(datestr(xticks))');
legend('14.57 mab','Location','northwest');
subplot(4,1,2);%minidot DO
plot(miniTtime, miniTDO);
hold on;
plot(miniMtime, miniMDO);
hold on;
plot(miniBtime, miniBDO);
ylabel('Dissolved Oxygen');
legend('Top (13.5 mab)','Middle (8.95 mab)','Bottom (1.07 mab)','Location','northwest');
ylim([4 15]);
datetick;
xlim([t1 t2]);
xticks=get(gca,'xtick');
set(gca,'xticklabel',cellstr(datestr(xticks))');
subplot(4,1,3);%sbe37 salinity
plot(time37,sal37,'.');
ylabel('Salinity');
ylim([33 34]);
datetick;
xlim([t1 t2]);
xticks=get(gca,'xtick');
set(gca,'xticklabel',cellstr(datestr(xticks))');
legend('13.65 mab','Location','northwest');
subplot(4,1,4);%minipar
plot(time_par,PAR);
ylim([0 200]);
ylabel('PAR');
datetick;
xlim([t1 t2]);
xticks=get(gca,'xtick');
set(gca,'xticklabel',cellstr(datestr(xticks))')
legend('0 mab','Location','northwest');
Heidi Hirshhttps://de.mathworks.com/matlabcentral/profile/authors/6143971-heidi-hirshtag:de.mathworks.com,2005:Question/2758542016-03-28T21:57:39Z2018-12-10T16:35:13ZN-Dimensional smoothing spline weightingIs anybody aware of how to use the weighting option of the csaps function for N-dimensional matrices? As an example, I can currently call csaps to fit a smoothing spline to a 2D MxN image, I, with a command like:
x = {1:M, 1:N};
spl_smooth = csaps(x, I);
I would like to fit a smoothing spline using a weighting matrix that has the same dimensions as the input image but it does not appear that I can do this with csaps since the weighting input argument must be a cell array with the same number of entries as the first input, x. This makes the size of the weighting argument {1xM, 1xN}, whereas I want it to be MxN.
Thank you for any help you can offer,
AveryAvery Bermanhttps://de.mathworks.com/matlabcentral/profile/authors/4281662-avery-bermantag:de.mathworks.com,2005:Question/4349822018-12-10T16:32:58Z2018-12-10T16:34:28ZAns given as 125*pi, how to change?What command do I use to change the answer in the form 125*pi to a number with decimals.
Thanks.Thomas Crombiehttps://de.mathworks.com/matlabcentral/profile/authors/14039753-thomas-crombietag:de.mathworks.com,2005:Question/4349812018-12-10T16:29:36Z2018-12-10T16:29:36ZHow to tell MATLAB where fortran compiler is?I have Intel Parallel Studio XE 2018 Update 1, Visual Studio 2017, and Windows 10. In MATLAB I ran "mex -setup FORTRAN" or "mex -setup -v FORTRAN", MATLAB couldn't file IFORT_COMPILER18. There was IFORT_COMPILER18 with value C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.1.156\windows\. What should I do so that MATLAB can recognize IFORT_COMPILER18?Tuan Phamhttps://de.mathworks.com/matlabcentral/profile/authors/4235759-tuan-phamtag:de.mathworks.com,2005:Question/4349792018-12-10T16:26:45Z2018-12-10T16:29:21ZWhy is 2014b faster?I am running data through simulink programs that have been designed others. Infact I am attempting to automate the whole process. Most interesting to me though is my automation program is vastly slower than simply running the programs manually. I have discovered that this is due to the difference in matlab versions. I turns out that if I run the manual code in 2014b, one file will take about 3-4min to complete. However, with 2017b, it takes somewhere around 25min. This is baffling to me, only because I likely lack the experience in simulink to understand what is going on.
For solutions I only have a few which I feel are not very ideal:
I rewrite some of my automation code to work with 2014b. Unfortunalty it looks like there are a number of functions that do not exist in 2014b, (such as some folder searching functions). This may work, but I may as well be starting over with my efforts to automate the process. Also 2014b is of course not ideal to work in these when we have newer versions available.
I have read there are ways to speed up simulink through with different levels of acceleration. I don't know if my case would benifit from that, or if its allready been done.
In short, simulink seems to running very slow on newer versions of matlab as much as 8x times as slow. I hope to find a solution that is sustainable for future improvments of the tools we have built using MATLAB. Hopefully its a lack of experience, that this stems from.
Thanks so much for your help in adavanced.Chase Wardhttps://de.mathworks.com/matlabcentral/profile/authors/13538573-chase-wardtag:de.mathworks.com,2005:Question/184012011-10-16T00:45:20Z2018-12-10T16:28:29ZPlease help! "Error: Function definitions are not permitted in this context. "Hello! I'm extremely new to Matlab, and I'm working on a homework problem, and I keep coming up with an error... I've written my functions, and defined some variables to be plugged into them. I can't even call my functions, because I get the error for writing them.
This all has to be in one m-file so I cannot save the functions in different ones... I'm not sure what to do :(
function [x,y,vx,vy] = trajectory(t,v0,th0,h0,g)
x = v0 .* cos(th0) .* t;
y = h0 + (v0 .* sin(th0) .* t) - ((1./2) .* g .* (t.^2));
vx = v0 .* cos(th0);
vy = (v0 .* sin(th0)) - (g .* t);
function y = height(t,v0,th0,h0,g)
[x,y,vx,vy] = trajectory(t,v0,th0,h0,g);
%(b)
v0 = 20;
th0 = 45;
h0 = 5;
g = 9.81;
t = linspace(1,4,400);
y = height(t,v0,th0,h0,g)Agatahttps://de.mathworks.com/matlabcentral/profile/authors/3120512-agatatag:de.mathworks.com,2005:Question/4349722018-12-10T16:06:14Z2018-12-10T16:28:29ZMultiple Linear Regression functionHello,
I need to do a linear regression to predict X (n*1 Matrix) with the 2features (N*2 Matrix), I tried with the function regression but it s not possible with more then a feature is there any other function I can use?Hayfa Robbanahttps://de.mathworks.com/matlabcentral/profile/authors/12783524-hayfa-robbanatag:de.mathworks.com,2005:Question/4349782018-12-10T16:25:21Z2018-12-10T16:27:49Zrng(s) takes previous seed instead of current oneI've encountered this problem when using functions in combination with user input and rng(s). To clarify my problem, I've got the following 2 scripts:
%main.m
user_seed = "1739995225";
disp(['Main input seed = ' char(user_seed)]);
checkSeed(user_seed)
and
%checkSeed.m
function checkSeed(user_seed)
%clear s seeder;
seeder = double(user_seed);
%check if seed isset
if exist('seeder','var') == 1
s = rng(seeder);
disp(['Function seed = ' num2str(s.Seed)]);
else
s = rng('shuffle');
disp(['random seed = ' num2str(s.Seed)]);
end
end
The issue is that everytime the previous user seed is being used instead of the current one. For example
%first run
user_seed = "1739995225";
%Main input seed = 1739995225
%Function seed = 1739995225
%second run
user_seed = "1739995226";
%Main input seed = 1739995226
%Function seed = 1739995225
%third run
user_seed = "1739995227";
%Main input seed = 1739995227
%Function seed = 1739995226
I tried putting the checkSeed.m contents in the main script, but that gave me the same result. Also tried adding clear s seeder; to the function but that didnt help either. So any ideas?YThttps://de.mathworks.com/matlabcentral/profile/authors/5583973-yttag:de.mathworks.com,2005:Question/4349592018-12-10T14:57:48Z2018-12-10T16:26:04ZHow do I make EXTRAPVAL a scalar?ex[Y,Z]=meshgrid(5:5:35,10:5:90);
cl=reshape(v,17,7);
cd=reshape(w,17,7);
bal=reshape(x,17,7);
Map1=interp2(cl,cd,bal,a,b);
surf(Map1,Y,Z)
v, w, and x all represent xlsreads. a and b are single numbers prompted by the user.
I am trying to graph these points on a 3d surface plot, but I always get the error using interp2: EXTRAPVAL must be a scalar. When I move certain variables around, the error then becomes: not monotonically increasing.
Please help, I can not figure this out.Cory Runnellshttps://de.mathworks.com/matlabcentral/profile/authors/13964780-cory-runnellstag:de.mathworks.com,2005:Question/4193202018-09-17T07:17:08Z2018-12-10T16:24:37ZStereo Convolution Reverb (VST audio plugin)Dear everyone
I am trying to generate vst, simple convolution reverb.
What is wrong?
classdef Stereo_Convolver_Basic < audioPlugin
properties (Constant)
% audioPluginInterface manages the number of input/output channels
% and uses audioPluginParameter to generate plugin UI parameters.
PluginInterface = audioPluginInterface(...
'InputChannels',2,...
'OutputChannels',2,...
'PluginName','Stereo Convolver'...
);
IR = audioread('./IR/st_georges_far.wav');
PartitionSize = 1024;
end
properties(Access = private)
pFIR_L = dsp.FrequencyDomainFIRFilter('Numerator', plugin.IR(:,1).', ...
'PartitionForReducedLatency', true, 'PartitionLength', plugin.PartitionSize);
pFIR_R = dsp.FrequencyDomainFIRFilter('Numerator', plugin.IR(:,2).', ...
'PartitionForReducedLatency', true, 'PartitionLength', plugin.PartitionSize);
end
methods
function y = process(plugin,u)
x = u(:,1)+u(:,2);
x = x * 0.5;
yL = step(plugin.pFIR_L,x);
yR = step(plugin.pFIR_R,x);
y = [yL,yR];
end
end
endSatoshi Suzukihttps://de.mathworks.com/matlabcentral/profile/authors/10960314-satoshi-suzukitag:de.mathworks.com,2005:Question/4340302018-12-05T15:50:40Z2018-12-10T16:23:10ZExport data into excel I keep getting this error.....
Index in position 1 exceeds array bounds (must not exceed 1).
Error in IHC_Continous_Quantification (line 28)
xlswrite('Staining.xlsx', percentage, 'B2:B3');
....from this code...
%Initialize
clc
addpath('/Users/benjaminreeves/Desktop/Test');
for i = 1:2
path = dir(strcat('/Users/benjaminreeves/Desktop/Test'));
filename = strcat(['im', num2str(i),'.tiff']);
images = imread(filename);
img = rgb2gray(images);
level = 0.60;
imbw = imbinarize(img, level);
imwrite(imbw, strcat('/Users/benjaminreeves/Desktop/Test/bwim/imbw', num2str(i), '.tiff'));
imtool(imbw);
total_pixels = numel(imbw);
total_white = nnz(imbw);
total_black = (total_pixels - total_white);
percentage = ((total_black/total_pixels)*100);
xlswrite('Staining.xlsx', percentage, 'B2:B3');
sprintf('The pecentage of imaged tissue, im%1.0f, that is stained is %.3f', i, percentage)
end
....I am brand new to coding and just trying to learn! No background at all.
Benjamin Reeveshttps://de.mathworks.com/matlabcentral/profile/authors/10968940-benjamin-reevestag:de.mathworks.com,2005:Question/4349742018-12-10T16:09:57Z2018-12-10T16:23:03ZHow can I get the main peaks from a signal with a lot of noises?I have a signal with a lot of noises and I would like to find those peaks that I have circled in the attached picture. I tried using findpeaks function with MinPeakHeight and MinPeakProminence options but I did not succeed. Thanksmarco tarusellihttps://de.mathworks.com/matlabcentral/profile/authors/5766798-marco-tarusellitag:de.mathworks.com,2005:Question/4335062018-12-03T12:56:55Z2018-12-10T16:20:35ZHow to find the first empty row of a .xlsx-file?I have a script in which I use writetable() to write data to a row in an excel spreadsheet. I need to get the row number of the next empty row in the file, but I haven't found a solution on this site.
Kind regards
MikkelMikkel Eskildsenhttps://de.mathworks.com/matlabcentral/profile/authors/8741399-mikkel-eskildsentag:de.mathworks.com,2005:Question/4349772018-12-10T16:20:17Z2018-12-10T16:20:17ZHow can i get my word-template based report out in pdf format?I am trying to generate a report via Matlab report generator, and i am successful in reproducing the example based on this code by Thomas Deck
https://se.mathworks.com/matlabcentral/fileexchange/56821-generating-custom-reports-with-matlab-report-generator-examples
But how can I get my report out in pdf format?Johnny Birchhttps://de.mathworks.com/matlabcentral/profile/authors/13117929-johnny-birchtag:de.mathworks.com,2005:Question/4349672018-12-10T15:41:24Z2018-12-10T16:19:46ZCall a Matrix inside another ScriptI want to achieve:
1. psm_q is a script.
2. When I am in main.m, type
psm_q;
psm_q will be shown in the workspace as a 6*1 matrix with values defined in psm_q.m
Let's say the 6*1 matrix of psm_q is [pi/3; pi/3; 0.1; pi/3; pi/3; pi/3], what should I code in psm_q?
I tried typing in psm_q:
[pi/3; pi/3; 0.1; pi/3; pi/3; pi/3]
,
[q1=pi/3;
q2=pi/3;
q3=0.1;
q4=pi/3;
q5=pi/3;
q6=pi/3]
and
function [q1,q2,q3,q4,q5,q6]=psm_q()
q1=pi/3;
q2=pi/3;
q3=0.1;
q4=pi/3;
q5=pi/3;
q6=pi/3;
end
but they all don't work as expected.
Please help.Laurel Castillohttps://de.mathworks.com/matlabcentral/profile/authors/14268037-laurel-castillotag:de.mathworks.com,2005:Question/4349572018-12-10T14:56:39Z2018-12-10T16:19:12ZHow to remove the first element of 13 * 20 array which is of data type Double?I have an array of 13 * 20 which is in Double, i would like to remove the first element of the first column and would like to keep the result stil in Double, I have provided the data in the excel attached, PFA.raghavendra kandukurihttps://de.mathworks.com/matlabcentral/profile/authors/12349470-raghavendra-kandukuritag:de.mathworks.com,2005:Question/4349762018-12-10T16:19:07Z2018-12-10T16:19:07ZHow to use lsim with changing values of sys.I am running this code:
A21 = -inv(M)*K;
A22 = -inv(M)*C;
AA = [A11 A12; A21 A22];
BB = [zeros(NN,1); M\Q];
CC = [zeros(1,2*NN)];
CC(8) = 1; % decides which value to pull
% For CC, first NN are position, 2nd NN are acceleration
DD = [0];
% -------------------------------------------------------
% -------------------------------------------------------
% Short Simulation
time = (0:.01:22.5)';
%P = 0*(time+1)./(time+1);
%P(1) = 500;
%P(2) = 500;
SYS = ss(AA,BB,CC,DD);
[YY, TT] = lsim(SYS, P, time);
% -------------------------------------------------------
However, I did not take into account that my BB matrix has changing values with time.
Is the correct way to do this to put the lsim function inside of a for loop or to place all of these lavues within the lsim function line and and have the BB variable dependent upon time.
Or is there a better way to do this?
To better explain myself, is this best way:
[YY, TT] = lsim(ss(AA,"some function of time for BB",CC,DD), P, time);
and then remove the "SYS=" line.Jesse Crottshttps://de.mathworks.com/matlabcentral/profile/authors/6941229-jesse-crottstag:de.mathworks.com,2005:Question/4342862018-12-06T19:01:59Z2018-12-10T16:16:58Zcan i discretise a transfer function in "butter" toolbox Matlab?
hi,
if I use the following command, does that make sense for discretisation? or i need to use "c2d" toolbox matlab for that ?
can anyone help me with that.
thanks in advance
the code is for :
A high-pass filter with a cut-off frequency of 0.02 Hz
A model whose filter is a first-order lag system (n=1). And Sampling time: 0.01 s;
n=1;
Wn=0.02; %Hz
% Transfer Function design
[b,a] = butter(n,Wn,'high');
figure;
freqz(b,a,(2*59400),0.01)
ADNAN KIRALhttps://de.mathworks.com/matlabcentral/profile/authors/12274816-adnan-kiraltag:de.mathworks.com,2005:Question/4349752018-12-10T16:10:27Z2018-12-10T16:14:19ZHow to calculate and plot area under the curve using trapz or other appropriate function?!I am trying to find and visualise the area under the curve for my data (see below) in order to compare to similar learning curve data. I have tried some ways but unsure if they are the most appropriate or have worked correctly as the data is negative and not smooth.
Any help would be much appreciated (still trying to learn the ropes with matlab).
Thanks
x y
1 -55.162559
2 -51.49817
3 -46.321619
4 -43.674017
5 -37.015529
6 -33.266756
7 -33.052172
8 -30.351532
9 -25.077227
10 -24.418889
11 -24.699318
12 -23.214323
13 -18.825947
14 -19.187909
15 -19.950888
16 -21.360635
17 -16.625949
18 -14.793957
19 -14.95093
20 -16.379339
21 -15.486643
22 -16.368055
23 -16.931243
24 -13.441767
25 -12.510163
26 -12.067308
27 -13.764358
28 -15.241232
29 -15.239815
30 -11.739023
31 -11.895491
32 -10.73586
33 -14.062533
34 -12.332744
35 -11.66472
36 -11.918313
Matthew Weightmanhttps://de.mathworks.com/matlabcentral/profile/authors/9318538-matthew-weightmantag:de.mathworks.com,2005:Question/4348132018-12-10T00:42:02Z2018-12-10T16:13:09ZDifferences between using region props and image J for perimeter estimateHi,
I am using matlab to countthe number of blobs in an image. I have my pixel to nm conversion
1 pixel = 0.361565 nm
I am sectioning the image in matlab then using regionprops to measure the perimeter. The values were higher than expected.
So as a way of checking it, I took the sectioned filtered BW image and used imageJ to get the perimeter. The values are significantly different and it's not a constant factor.
Here is an example :
These are the values from ImageJ
These are the results from regionprop
AIDA AMROUSSIAhttps://de.mathworks.com/matlabcentral/profile/authors/5267625-aida-amroussiatag:de.mathworks.com,2005:Question/4346512018-12-08T21:51:13Z2018-12-10T16:13:08Zneed solution of exerciceKHAIF HICHEMhttps://de.mathworks.com/matlabcentral/profile/authors/14165008-khaif-hichemtag:de.mathworks.com,2005:Question/4348032018-12-09T23:00:31Z2018-12-10T16:08:24ZHow to add scalar to empty matrix?Can I make an empty matrix behave as zero when adding/subtracting/ a scalar with such an empty matrix?
Suppose you have the following for loop
result = zeros(5,1);
for k=1:5
result(k) = k^2 + ones(k-1,1)*5;
end
On the very first loop I will have 1^2 + []*5, and this will return an empty vector. I can obviously change the starting point for k to 2 to avoid this issue. However the problem I have is a more complicated version, and in some cases the starting point for the loop will be random. I would like to obtain k^2+[]*5 = k^2; treat the empty matrix as a zero, but matlab will just return an empty vector. Is there any way of converting an empty matrix into zero, and keeping the matrix if its not empty?Random goosehttps://de.mathworks.com/matlabcentral/profile/authors/7414631-random-goosetag:de.mathworks.com,2005:Question/4349732018-12-10T16:08:06Z2018-12-10T16:08:06ZRemoving noise in a Curvature profile, in case of a trajectory consisting of Line and circular arcs.Hi,
I have a 2D Trajectory as shown below:
Using the function LineCurvature2D.m, I found the curvature profile for the above trajectory.
It is as shown below:
But the above curvature profile is really noisy.
I am actually, trying to find the critical points for my trajectory.Critical points are the points,where Line is changed to Arc.
In General, critical points are obtained by finding the local maxima of the curvature profile.
But in my case,I have really noisy data and hence,I am not able to find the peaks exactly.I Have read some papers,where researchers are using some kind of "Quadra filter" to manage this noisy curvature profile data.
I would be really glad,if someone can suggest me the approach in my case.
Please feel free to suggest any other approach,through which,I can find correct breakpoints.
In the above trajectory,I would expect to find 4 breakpoints,as I have two circular arcs and 3 straight lines,like below:
Blue circles indicate the breakpoints in the below Image.
Please help! Thanks!Math Enthusiasthttps://de.mathworks.com/matlabcentral/profile/authors/13894418-math-enthusiasttag:de.mathworks.com,2005:Question/4344812018-12-07T17:35:06Z2018-12-10T16:04:13ZLabel rows and columns of subplotsI have six figures (in .fig format) and would like to arrange them in a 2x3 subplot and then label each row and column of subplots. In specific, I want to label the two rows 'Participant 1' and 'Participant 2', and the three columns 'Frequency set 1', 'Frequency set 2' and 'Frequency set 3'.
Below is the code I tried:
% give the path of .fig to be plotted together
figName1 = '/.../participant1/freqSet1.fig';
figName2 = '/.../participant1/freqSet2.fig';
figName3 = '/.../participant1/freqSet3.fig';
figName4 = '/.../participant2/freqSet1.fig';
figName5 = '/.../participant2/freqSet2.fig';
figName6 = '/.../participant2/freqSet3.fig';
% list all variables starting w/ 'figName'
figList = who('figName*');
% Load saved figures
fig1=hgload(figName1);
fig2=hgload(figName2);
fig3=hgload(figName3);
fig4=hgload(figName4);
fig5=hgload(figName5);
fig6=hgload(figName6);
% Prepare subplots
figure
for iSubPlot = 1:length(figList)
h(iSubPlot) = subplot(2,3,iSubPlot);
if iSubPlot==1
text(-0.35, 0.5,'Participant 1');
text(0.35,1.1,'Frequency set 1');
elseif iSubPlot==2
text(0.35,1.1,'Frequency set 2');
elseif iSubPlot==3
text(0.35,1.1,'Frequency set 3');
elseif iSubPlot==4
text(-0.35, 0.5,'Participant 2');
end
end
% now the desired labels have been applied
% Paste figures on the subplots
copyobj(allchild(get(fig1,'CurrentAxes')),h(1));
copyobj(allchild(get(fig2,'CurrentAxes')),h(2));
copyobj(allchild(get(fig3,'CurrentAxes')),h(3));
copyobj(allchild(get(fig4,'CurrentAxes')),h(4));
copyobj(allchild(get(fig5,'CurrentAxes')),h(5));
copyobj(allchild(get(fig6,'CurrentAxes')),h(6));
% now the subplots are pasted, the previous row and column labels are gone
As described in the code comments, the row and column lables disappear after I paste the figures into the subplot. Do you know how I can fix this? Thanks very much!Hellen Jing Yuanhttps://de.mathworks.com/matlabcentral/profile/authors/13082400-hellen-jing-yuantag:de.mathworks.com,2005:Question/4349662018-12-10T15:40:18Z2018-12-10T16:01:46ZHow to insert a n x m matrix or table, into an existing table?Hello,
I would like to nest an n x m matrix into a table, by using a for loop to populate each row of the table with a corresponding matrix. I am running matlab 2018a. Below you can find example code:
% create the table
subject = [1; 2; 3; 4];
condition = {'cond1';'cond2';'cond3';'cond4'};
data = NaN(4,1);
T = table(subject,condition,data);
% populate the table with matrixes, using a for loop
for i = 1:1:size(T,1)
data = rand(10,5);
T.data(i) = data; % ERROR Unable to perform assignment because the left and right sides have a different number of elements.
end
I thought it was possible to create nested tables. However, I am not sure, on account of the error. I know tables within tables exists, but I am unsure whether you can nest a matrix/array in a table. Therefore, it is also allowed to transform the data matrix to a table, and then nest the table in the table. Of importance, I want to retain the for loop mechanism to populate the table.
Thanks in advance,
Jens
Jens Allaerthttps://de.mathworks.com/matlabcentral/profile/authors/9324572-jens-allaerttag:de.mathworks.com,2005:Question/4349692018-12-10T15:51:38Z2018-12-10T15:59:27Zhow to write in Matrixdear all
how to write in matrix this equation
v = -(k./mu).*(grad(p) - (rho*g*dz);
P = (1/dt)*(pv*rho) + div(rho*v)
thank you
vyvaya putrahttps://de.mathworks.com/matlabcentral/profile/authors/10428756-vaya-putratag:de.mathworks.com,2005:Question/4338452018-12-04T21:50:47Z2018-12-10T15:57:15ZMaximum Number of UIAxes in App Designer 2017bHi!
I recently have been tasked with building a large GUI in Matlab App Designer. After finally finishing placing all the UI elements, I notice that my plotting functions no longer work when calling them. The figures that these plotting functions relate to are also not visible, but still contained in the GUI object. There are no errors reported for this, but rather the GUI refuses to update those plots. The rest of the data is visible on other tabs and the GUI is still functional.
After a bit of searching on other issues related to this, I found this post: https://www.mathworks.com/matlabcentral/answers/327311-why-do-app-designer-uiaxes-elements-start-to-disappear?s_tid=answers_rc1-2_p2_MLT which mentions a limit of 16 axes that was supposed to be fixed for 2017a. The GUI has well over 100 UIAxes in the app currently, so I'm wondering if there is a new limit within MATLAB.
Thanks!
EDIT: I have attached an error that showed up probably 20 minutes after clicking the plot menu action.Chas Frickhttps://de.mathworks.com/matlabcentral/profile/authors/10370989-chas-fricktag:de.mathworks.com,2005:Question/3104942016-11-03T14:30:07Z2018-12-10T15:55:27ZIncremental table writing from datastoreNeed a solution. Want to read big data files incrementally (T = read(ds)), create a new variable from a calculation, and write that new variable "X" into a new CSV...but MATLAB is not allowing. Here's the code (the source CSV files are not here):
ds.SelectedVariableNames = {'time','lat','lon'}
OutFileName = 'temp.csv'
while hasdata(ds)
T = read(ds);
LAT = T.lat;
LON = T.lon;
AVG_LAT = mean(LAT);
AVG_LON = mean(LON);
writetable([T, AVG_LAT, AVG_LON], OutFileName)
end
The Output file must be 1 file only, not multiples...similar to using fprintf(...'a+') for appending instead of overwrite. "Writetable" handles T fine as an output, however, when adding the calculated fields (AVG_LAT, AVG_LON), the merged table results in a [n x m Table] [double] array...THAT does NOT work with writetable.
Need a solution to write X into the output table with T. T represents the datastore (ds) with my SelectedVariableNames.
VERSION 2016bTom Whttps://de.mathworks.com/matlabcentral/profile/authors/2311558-tom-wtag:de.mathworks.com,2005:Question/4335192018-12-03T14:05:24Z2018-12-10T15:54:32Zmatlab sounds in game designSay I build a snooker game, where balls need to jitter around. I added a sound when balls collide, importing a sound file. But playing a sound turns out to slow down the program quite a lot, as I observe substantial pauses, which look bad. I use matlab. Is it just because matlab is slow?a ahttps://de.mathworks.com/matlabcentral/profile/authors/11974203-a-atag:de.mathworks.com,2005:Question/4344572018-12-07T15:28:47Z2018-12-10T15:51:42ZCan someone give an example of a for loop for this problem?: Find the sum of 30 numbers that increments by 3. The starting number is 4. Thanks!Just a simple for loop please. Nothing too complicated. Thank you again.TSmithhttps://de.mathworks.com/matlabcentral/profile/authors/13527208-tsmithtag:de.mathworks.com,2005:Question/4349682018-12-10T15:50:30Z2018-12-10T15:50:30ZHow to use an user input to generate new input fieldsHello, I am new to matlab and I am starting to experiment with the App Designer. I am trying to make a simple NPV calculator. I would like to have the user input the number of cashflows (periods) into a field and have the app generate the corresponing amount of fields so the user can input every cashfow separatly.
Ex. if the user enters 4 in the period field, 4 more fields appear so the user can fill them in.
I hope this makes sens. Thank you for you help!Mathieu Loisellehttps://de.mathworks.com/matlabcentral/profile/authors/14149089-mathieu-loiselletag:de.mathworks.com,2005:Question/4243532018-10-16T19:12:30Z2018-12-10T15:44:44ZUnable to connect to the 'TI Delfino F2833x (boot from flash)' target..Hi,
i'm developping a Simulink schematic to drive MOSFETs with a f28335 DSP(Clock 150Mhz). I'm using 4 ADC input ports (Inputs) and drives 4 ePWM (2 times active high complementary A&B).
I don't have any issue with the DSP itself, but when I build the code on it, the DSP 'disconnect' from the computer, so I can't read the scope in my schematics. The code continue to run normally on the DSP, but I don't have access to the scopes, which is not usefull.
Here's the error i have:
_Error occurred while executing External Mode MEX-file 'ext_comm':
Failed to connect to the target. A time-out occurred while waiting for the connection response from the target. Possible reasons for the time-out:
a) The target is not switched on.
b) The target is not connected to your host machine.
c) The application for the model is not running on the target. You might have clicked the Stop button. If the Run button is not dimmed, click it. Otherwise, click the Build button, which downloads and runs your application on the target.
Component:Simulink | Category:Block diagram error
Unable to connect to the 'TI Delfino F2833x (boot from flash)' target for 'PID_Twist_DSP_f28335slx'._
With the f28069 DSP (Clock 90Mhz) , i don't have this issue.
Does anyone have any idea where this is coming from ?
Thanks
Charles Gagné-Carrierhttps://de.mathworks.com/matlabcentral/profile/authors/7560069-charles-gagne-carriertag:de.mathworks.com,2005:Question/4214462018-09-30T06:09:34Z2018-12-10T15:43:59ZR2018b runs very slow on macOS 10.14Hi everyone,
I am using macOS 10.14 (Mojave) and just upgraded the MATLAB to R2018b yesterday and found a very strange problem. The editor runs EXTREMELY slow on my system and often freezes. When I click on somewhere on the editor or scrolling the view it usually takes 1-2 secs to response.
However, the strange point is, the problem only occurs when the MATLAB window is displayed on my external monitor. When I move the window to the macbook's internal monitor, everything is normal. And, the problem does not show on some specific files. I don't know if there are any features of those file, but if I make copies of those files, the problem may shows on the copies again.
I am not sure if it is a problem of MATLAB or my OS. How is the R2018b running on your systems? Chang Liuhttps://de.mathworks.com/matlabcentral/profile/authors/13139737-chang-liutag:de.mathworks.com,2005:Question/4335602018-12-03T16:40:05Z2018-12-10T15:38:58ZFitting multiple geometrical entities into a given 2D TrajectoryHi,
I have two dimensional data (containing x and y coordinates data).I want to fit multiple 2D Geometrical entities such as Line,circle,ellipse and arc into this data
For example, in the attached image (Rectangle.jpg), I want to fit 4 lines into it and make it a rectangle or square.
Similarly,in the attached image (ZigZag.jpg), I want to fit 5 lines.
In the attached image (Line_ArcCombined.png) file,I would like to fit 3 Lines and 2 arcs.
Basically,I would like to fit multiple geometrical entities into a given 2D Trajectory data (consisting of x,y vertices data).
I would be really glad,if someone can give me any idea/references to achieve it.
Thanks a lot in advance!MathWorksMath Enthusiasthttps://de.mathworks.com/matlabcentral/profile/authors/13894418-math-enthusiasttag:de.mathworks.com,2005:Question/4346162018-12-08T16:55:59Z2018-12-10T15:38:37ZHow to fit linear plateau equation ?I want to fit linear equation with plateau condition.
y=a(x+n)+b
These are the data in which I Want to fit:
x=[0,80,100,120,150],
y=[1865,3608,4057,4343,4389]
I don not know how to find the plateau value of yield.
madhuri dubeyhttps://de.mathworks.com/matlabcentral/profile/authors/6208172-madhuri-dubeytag:de.mathworks.com,2005:Question/4349532018-12-10T14:28:32Z2018-12-10T15:38:13Z[Log plot] How to make variable tick format (major in 10^%d format, minor in %d format)?Hello,
Briefly, I'm plotting this graph:
and I would like to get something like this:
Is that possible? Could anybody help me, please?Youngboarhttps://de.mathworks.com/matlabcentral/profile/authors/7527164-youngboartag:de.mathworks.com,2005:Question/4349542018-12-10T14:41:19Z2018-12-10T15:34:37ZTrying to create a plot with a line as shown in the pictures my code: im using a for loop to create a graph and plot as it works out but i can only get the graph to look like the first pic below, what would be the lines of code to get it to look like the second graph? (just one line ofcourse i couldnt find another one on the internet) thanks for the help!
figure(1)
plot(t,Tin,'--xb')
title('Room temperature over time for Tlower=21^oC and Tupper=24^oC')
xlabel('Time(s)')
ylabel('Temperature(degrees)')
hold on
barry conradhttps://de.mathworks.com/matlabcentral/profile/authors/14290045-barry-conradtag:de.mathworks.com,2005:Question/4349652018-12-10T15:32:04Z2018-12-10T15:32:04ZAdding standard deviation as a bar to a scatter plotHello all, I'm plotting weather data and want to show the mean, standard deviation and min-max values in one plot. I've attached a photo of the ideal end result. How might I go about it using the data below as an example?
Mean_Temp_1 = [12]
Mean_Temp_2 = [15]
Mean_Temp_3 = [11]
SD_1 = [1.2]
SD_2 = [0.8]
SD_3 = [1.4]
Max_1 = [14]
Max_2 = [17]
Max_3 = [12]
Min_1 = [10]
Min_2 = [12]
Min_3 = [10]Joseff Saundershttps://de.mathworks.com/matlabcentral/profile/authors/9193833-joseff-saunderstag:de.mathworks.com,2005:Question/4349642018-12-10T15:31:45Z2018-12-10T15:31:45Z Search and comparison in the imageHello,
I have an image that has an object. I found the center of this object (the intersection of row and col). Now I need from the found center (the intersection of row and col) with a certain step, row + 5pxl, row - 5pxl, col +5 pxl, col - 5pxl, and so on, to compare the sum of the resulting rectangle with the sum of the values of the whole image until it is satisfied the condition Zf> = Zall, where Zf is the sum of the found values of the rectangle, and Zall is the value of the entire image.
A=imread('something.jpg');
A=rgb2gray(A);
V=sum(A');
ROWS=size(A,1);
Otn=sum(A(:));
for trow=1:ROWS
st=sum(V(1:trow));
sb=sum(V(trow:ROWS));
temp=abs(st-sb);
if temp<Otn
Otn=temp;
row=trow;
else
break;
end;
end
row
Otn
W=sum(A);
COLS=size(A,2);
Otn=sum(A(:));
for tcol=1:COLS
sl=sum(W(1:tcol));
sr=sum(W(tcol:COLS));
temp=abs(sl-sr);
if temp<Otn
Otn=temp;
col=tcol;
else
break;
end;
end
col
Otn
A((row-4):(row+4),:)=100;
A(:,(col-4):(col+4))=100;
colormap(gray(256));
image(A)
how do i make this cycle? thank you for help!
Vasilii Krimeanhttps://de.mathworks.com/matlabcentral/profile/authors/14339753-vasilii-krimeantag:de.mathworks.com,2005:Question/4344272018-12-07T13:21:00Z2018-12-10T15:29:03ZHow to adjust luminance of multiple videos so that the luminance is uniform across videos?Hi all,
I need to adjust the luminance ofa set of videos, so that they have roughly the same level of luminance. I can't seem to find any example of this with videos, so any hint of how this can be achieved is very much appreciated.
Best wishes,
HelioHelio Cuvehttps://de.mathworks.com/matlabcentral/profile/authors/13184806-helio-cuvetag:de.mathworks.com,2005:Question/4348712018-12-10T09:27:05Z2018-12-10T15:26:33ZMATLAB memory allocation problemHi,
I am running my matlab code (which is only a line such as;
[fis_norm,trainError,stepSize] = anfis(sq_train_long);
however it takes more than 10 min. My data sq_train_long is an array (50.000x7 double)
Here my system info;
MATLAB 2018a
Windows Server 2016
processor:Intel Xeon CPU E3 1275 3,5Ghz
installed memory:24GB
Response of "memory" command in MATLAB is below;
>> memory
Maximum possible array: 39849 MB (4.179e+10 bytes) *
Memory available for all arrays: 39849 MB (4.179e+10 bytes) *
Memory used by MATLAB: 1865 MB (1.956e+09 bytes)
Physical Memory (RAM): 24475 MB (2.566e+10 bytes)
* Limited by System Memory (physical + swap file) available.
Below, you can se what I have tried so far;
Give higher priority to Matlab.exe task on task manager
Increase the page file size of your applications in general. currently :20,000 MB
Performance Settings, it is set for "Programs" and not for "Background services". "Programs" is the default.
Visual effects tab of "performance options" is set to "Adjust for best performance"
Matlab Preferences- Workspace- unchecked "Limit the maximum array size to a pecentage of RAM"
Matlab Preferences- Workspace - jAVA Heap Size updated to max 12,236MB (which is the max value on preferences window)
Parpool - I have used paralled processing but didn't shortened the elapsed time at all.
Please help me on this. I've read and applied all the advice on this matter. some of the answers were asking for more detailed questions. I hope this one would give more information on the problem.aycan ayyilmazhttps://de.mathworks.com/matlabcentral/profile/authors/11486770-aycan-ayyilmaztag:de.mathworks.com,2005:Question/4342472018-12-06T15:01:16Z2018-12-10T15:25:21ZFinding local maxima on a slightly noisy dataHi,
I have my plot,as shown in "Trajectory.png" file.
My X-Axis data is just:
Xdata = [1:100];
My Y-Axis data is as follows:
0
0
2.09222708159463
6.44546159330348e-07
2.09222611499462
1.13686837721616e-13
1.19629985182991
0.307031063055145
0.889191608677226
1.13686837721616e-13
1.13686837721616e-13
0
1.13686837721616e-13
1.13686837721616e-13
0
1.13686837721616e-13
1.02297834274279
0.0388633487946145
1.06185167072739
1.13686837721616e-13
0.361256176978336
0.609935965840200
0.219116803722684
0.752088093054083
1.13686837721616e-13
0
1.13686837721615e-13
1.13686837721617e-13
1.13686837721616e-13
12.7332583247782
144.877119357353
2.09424951365800
0.947857561548907
1.15967343285703
5.85842059479906
7.90599054430073
1.03340833244700
1.74611749440277
1.25454771605403
0.405678614930056
3.32781000899039
0.540378086763468
1.98803176650120
1.37173336776097
2.03332435894425
4.19689864919353
2.11301835089563
7.88897972952186
46.5756563901977
3.01603701789582
1.78266388299620
0.608273922686689
0.879773039416162
0.900317534766668
0.807217040648508
0.326548725644831
0.207175108036568
0.495172539519853
0.520077384058685
0.173410667917717
0.0642667898143524
0.131548850902771
0.161997164449503
0.0413293955654355
0.490113271390482
1.08274572574879
0.838386694466136
7.10542735760100e-15
0.0980279964920274
1.49459508834199
1.19798004219773
0.394520279605238
7.10542735760100e-15
7.10542735760101e-15
7.10542735760100e-15
1.47973128457182
0.718756197167734
0.382866238818068
2.58339794004342
2.10894362431230
44.0407985149444
98.6536822408392
7.40103735780748
2.22280189553396
1.99971342894857
2.71371333131814
5.99983968601066
2.57127665277943
5.68150302624610
0.257865115144954
0.0303588377283994
1.26389973299037
1.16741322335018
1.41971109494362
1.91582002185642
2.52274280044650
4.35828014515571
0.146871341252485
2.06696816496338
2.06293020725324
I want to find my local maxima for this plot.
In the plot,we can see that, there is a lot of noise.Due to this noise,When I try to find local maxima,with this function,I get around 16 points, instead of 3.
I am using the following code for finding local maxima:
[Maxima,MaxIdx] = findpeaks(K);
Here,K is Y-Axis data.(N x 1 data)
I would be really glad,if someone can explain,the procedure to remove the noise,so that finally,when we call the function to find Maxima,it gives us 3 values(i.e. at xvalues 31,50 and 82) instead of 16 values.
Math Enthusiasthttps://de.mathworks.com/matlabcentral/profile/authors/13894418-math-enthusiasttag:de.mathworks.com,2005:Question/4349452018-12-10T14:00:21Z2018-12-10T15:22:15ZOnly thing that I want to control is speed. not pitch.[Q, S] = audioread("sample.mp3");
speed = 1.2;
S = S * speed;
soundsc(Q,S);
This is what I do.
as you know, this code makes increase both pitch and speed.
but I want to make change only speed.
How can I control it?
**and How can I only control pitch?Daeil Junghttps://de.mathworks.com/matlabcentral/profile/authors/13967808-daeil-jungtag:de.mathworks.com,2005:Question/4348922018-12-10T10:41:58Z2018-12-10T15:22:10ZIssue with Simulink Model Simulation inside Parfor ?Hi,
I am trying to run multiple simulations with different data set on model 'ModelTest.slx' using parfor.
my code goes like this,
parfor
simout=sim(bdroot,<options>)
..
..
..
end
Parfor executes one simulation (sometime it runs two simulations). It geerates 'slprj' folder after first simulation.
Then it gets aborted with following error message.
"C:\Users\...\parllelTest\slprj\_jitprj\jitEngineAccessInfo.mat.
Not a binary MAT-file. Try LOAD -ASCII to read as text."
Below are the details of matlab version and model settings,
Matalb 2015b,
parpool with local profile.
Simulation Mode : Normal;
Solver :Fixed Step, discrete
Does anyone have any idea about this error. ?Shivaputra Narkehttps://de.mathworks.com/matlabcentral/profile/authors/3327626-shivaputra-narketag:de.mathworks.com,2005:Question/4349632018-12-10T15:20:22Z2018-12-10T15:20:22Zhow to detect green and yellow colour? X,map]=imread('fruit.png');
imshow(X,map)
p=ind2rgb(X,map);
diff_im = imsubtract(p(:,:,1), rgb2gray(p));
diff_im = medfilt2(diff_im, [3 3]);
diff_im = im2bw(diff_im,0.18);
diff_im = bwareaopen(diff_im,300);
bw = bwlabel(diff_im, 8);
stats = regionprops(bw, 'BoundingBox', 'Centroid');
hold on
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'blue');
end
hold off
Based on code above ,this one can detect red only . how to detect green pear and yellow lemon? which one to need to change?
Hyunn Nishttps://de.mathworks.com/matlabcentral/profile/authors/14279148-hyunn-nistag:de.mathworks.com,2005:Question/4349622018-12-10T15:18:58Z2018-12-10T15:18:58Zwhat algorithm on image processing should i use on classifying fertilized duck eggs? Im having a hard time on doing image processing on fertilized duck eggs. I need an output that the fertilized duck eggs are classified according to its state.Daren Almoitehttps://de.mathworks.com/matlabcentral/profile/authors/14039597-daren-almoitetag:de.mathworks.com,2005:Question/4348762018-12-10T09:48:32Z2018-12-10T15:15:57Zwhy I recive a notification about deactivationI receive a notification about a inmediate deactivate of license
Igor Carneroshttps://de.mathworks.com/matlabcentral/profile/authors/10267083-igor-carnerostag:de.mathworks.com,2005:Question/4349332018-12-10T13:08:28Z2018-12-10T15:14:04ZCannot connect to ROS master and connect my Baxter robot...Hi,i am a Chinese student and ye here again.
Recently,I got some problem and I have seen similar problems and solutions ，but the problem still a problem.
Accoding to
(1) https://www.mathworks.com/matlabcentral/answers/233109-cannot-access-ros-services,
(2)https://www.mathworks.com/matlabcentral/answers/119559-why-is-the-ros-subscriber-callback-in-matlab-not-triggered-when-messages-are-published-from-an-exter?s_tid=answers_rc1-2_p2_Topic
(3)https://www.mathworks.com/matlabcentral/answers/403046-turtlebot3-not-moving-with-ros-and-matlab-robotics-system-toolbox
https://www.mathworks.com/matlabcentral/answers/219780-r2015a-robotics-system-toolbox-cannot-subscribe-to-topics-on-windows-matlab-node
What i have done are as follows:
in matlab :
in my hosts file from C:\Windows\System32\drivers\etc.
and also i have the toolbox ,the firewall is closed .i download the communicator class from web,the code named StartHere_ExampleScript.m are as follows :
and it can connect my virtual machine ROS master ip 192.168.1.129，so i decide to connect my real Baxter robot ，but it is failed. ^--^//
So, I really need help to solve this problem. Then I can continue to learn and study the baxter robot.
Can you help me if you have solved a similar problem? I really appreciate your help.
Best wishes！
StartHere_ExampleScript - Script to test Baxter Communicator class
% Notes:
% 0) Execute this script section by section
% 1) If you are running on a laptop, you might need to disable your
% antivirus software.
% 2) Make sure to turn on Baxter with the E-Stop released.
% 3) This script will DISABLE Baxter's Collision Avoidance
% 4) Baxter's IP should be declared in the hosts file in C:\Windows\System32\drivers\etc
% 5) check that your antivirus is off and E-Stop is disabled
% Copyright 2017 The MathWorks, Inc
%% Connect to ROS MASTER
% Change '011310P0010.local' to your Baxter's hostname
% NodeHost should be the IP address of your laptop or host machine
% rosinit('011310P0010.local','NodeHost','192.168.244.129')
%% Create object of Baxter Communicator class
% To connect to hardware:
% for hardware
rosinit('011602P0019.local','NodeHost','192.168.1.128')
%%
% To connect to simulation:
%bc = BaxterCommWithSim(true); % for simulation
%rosinit('192.168.1.129')
%% Turn on Servos
enable(bc);
%% Start timer to periodically update the joint commands
%baxterStartTimerForRobot;
baxterStartTimerForSim;
%% Untuck both arms
untuck(bc, 3);
...............
snow Johnhttps://de.mathworks.com/matlabcentral/profile/authors/11711547-snow-johntag:de.mathworks.com,2005:Question/4349602018-12-10T15:01:34Z2018-12-10T15:12:53ZHow do I correctly use the Syntax of fmincon?I am trying to optimize a flight path. I have the following equations of motions:
dydt=(thrust*sin(alphat)/m*v)-gh*cos(y)-v*cos(y)/(re+h);
dvdt=(thrust*cos(alphat)/m)-Adrag* rhoh*(v^2)/2*m- gh *sin(y);
dhdt=v*sin(y);
dxddt=(re/re+h)*v*cos(y);
dmdt=-propflow;
dwdt=(1/Ix)*thrust*sin(alphat)*rs;
h and v are limited by the final orbit:
hmax=hfinal;
vmax=vfinal;
the downrange x and w are not constrained. I will set the max values of these parameters to a high value, which they will never reach.
m is the parameter that I want to maximize in my final orbit ans the flight path angle y should be equal to 0,because I want my rocket to reach a circular orbit.
Finally my alphat is the thrust vector control variable with which I would like to minimize my mass loss. So I would like fmincon to calculate my function alphat, so that my mass in the final orbit is as high as possible.
The problem is that I dont't understand how to define
A*x=b;
. Could someone here explain me what exactly A, x and b are and how I calculate them??
Thanks
Brendan Görreshttps://de.mathworks.com/matlabcentral/profile/authors/13254816-brendan-goerres