https://au.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-09-23T13:42:59Ztag:au.mathworks.com,2005:Question/4355132018-12-13T07:56:04Z2020-09-23T13:42:59ZHow can I label my graphs as (a), (b), (c) etc in subplot matlab? I want to describe the graphs in figure caption by referencing them as (a), (b) (c) etcShikhar Saxenahttps://au.mathworks.com/matlabcentral/profile/authors/9251201tag:au.mathworks.com,2005:Question/5983812020-09-23T09:06:44Z2020-09-23T13:42:45Zsimulink user defined matlab function outputs zero irrespective of inputI am using simulink user defined block to realise a difference equation. The function is defined as shown below.
function y = fcn(u)
a = [1 -2 1]; % left hand side of difference equation
b = [0 1 2]; % right hand side of difference equation
y=filter(b,a,u);
When I use this block independenly with some array as input, I am able to get the expected values. But when I use this block in another design, the output is always zero though the input is changing. Any suggestions on how to debug this ?Nithin Ravani Nanjundaswamyhttps://au.mathworks.com/matlabcentral/profile/authors/19551492tag:au.mathworks.com,2005:Question/5984202020-09-23T10:08:20Z2020-09-23T13:40:02Z'Array indices must be positive integers or logical values' error in my codeI have attached two codes here. when i try to run it, it gives the error 'array indices must be positive integers or logical values'. Now i tried initializing the code with initial values > 0. still the same error is occuring. Can someone help me clear it or tell me why is it so?Abhishek Varmahttps://au.mathworks.com/matlabcentral/profile/authors/19438321tag:au.mathworks.com,2005:Question/5984982020-09-23T12:35:06Z2020-09-23T13:40:01ZI am looking for a way to take the values from a matrix and sorting them into different empty arrays.Im looking for a way to take the values from matrix(given under) and sorting them into diffrent empty arrays (A and B).
A = char.empty;
B = char.empty;
vector1 = [1,0,0,0,0,1]';
vector2 = ([1,2,4,6,6,1])';
matrix = [vector2, vector1]
matrix =
1 1
2 0
4 0
6 0
6 0
1 1
My goal is to have the script recognize what values have a 1 behind it and what values have a 0 behind it so that A and B ends up looking something like this:
A = [1,1] %A being the array with values from matrix(:,1) that has a 1 in matrix(:,2)
B = [2,4,6,6] %B being the array with values from matrix(:,1) that has a 0 in matrix(:,2)
The ulttimate goal for the script segment is to have it funcion for any vector2, by manipulating vector1 from a zeroes vector using a menu system of sorts
%zero being the zeroes vector
zero = zeros(6:1)
%and want this to be manipulated using a menu or something to become a vector composed of
%ones and zeroes according to a selection in the menu
%so that it ends up looking like vector1 from the code above
Sorry if its badly formulated but my english is'nt the best in the world and my understanding of Matlab is a little subpar, so if you have questions about what im trying to achieve then feel free to ask. And thank you in advance for any help.
Tore Henriksen Eliassenhttps://au.mathworks.com/matlabcentral/profile/authors/19254765tag:au.mathworks.com,2005:Question/5984172020-09-23T10:02:05Z2020-09-23T13:38:55ZWhy does my app did not have the data and training panel?Fong Yu Shenghttps://au.mathworks.com/matlabcentral/profile/authors/16718676tag:au.mathworks.com,2005:Question/1298862014-05-16T14:46:52Z2020-09-23T13:36:41Zhow can i extract contour from my image ?hello everybody ,
i have done an thresholding , but my image is still contain parasites how can i clean that xena tequihttps://au.mathworks.com/matlabcentral/profile/authors/4812907tag:au.mathworks.com,2005:Question/5984772020-09-23T11:30:31Z2020-09-23T13:34:53ZI need help please, how can I write a program to count the number of digits of an integer the user entered ? For example, I asked the user to input a number and he entered 5984, how can I write a program to count how many digits it has (which is 4)? Thank you.Rodha Mhttps://au.mathworks.com/matlabcentral/profile/authors/19431637tag:au.mathworks.com,2005:Question/5985102020-09-23T13:11:50Z2020-09-23T13:33:46ZHow to save figures from a loop to current folder with specific namesMy Code shows 9 figures ( T=1:3 and b=1:3) in a loop and it saves in my current folder. But it saves as:
T1.pngT1
T1.pngT2
T1.pngT3
T2.pngT1
T2.pngT2
T2.pngT3... and so on
But I have 2 variables, so I want to to save them as:
T1b1
T1b2
T1b3
T2b1
T2b2
T2b3.... and so on
How can I do this?
clear all;
clf
n=100;
t0 = 0.5;
T = 1:3;
b = 1:3;
for v_T = 1:length(T)
for v_b = 1:length(b)
T_A = T(v_T)
b_A = b(v_b)
pdf2p = @(x) (b_A/T_A).*(x/T_A).^(b_A-1).*(exp(-(x/T_A).^(b_A)));
pdf3p = @(x) (x>t0).*(b_A/(T_A-t0)).*((x-t0)/(T_A-t0)).^(b_A-1).*(exp(-((x-t0)/(T_A-t0)).^(b_A)));
h= figure
fplot(pdf2p,[0,10], 'LineWidth',2, "Color", 'b')
hold on
fplot(pdf3p,[0,10], 'LineWidth',2, "Color", 'r', 'LineStyle', '--')
ax = gca;
ax.XLim=[0,2.5];
ax.YLim=[0,3];
grid on; %Gitter anzeigen
box on; %Rahmen zeigen
title ('2- und 3 parametrische Dichtefunktion für n=10');
xlabel('Lebensdauer t');
ylabel('Dichtefunktion f(x)');
legend(['T=' num2str(T_A), ', b=' num2str(b_A)], ['T=' num2str(T_A), ', b=' num2str(b_A), ', t0=' num2str(0.5)])
saveas(h,sprintf('T%d.png',T_A, b_A))
end
end
Mustafa Vuralhttps://au.mathworks.com/matlabcentral/profile/authors/10250393tag:au.mathworks.com,2005:Question/5985192020-09-23T13:23:26Z2020-09-23T13:32:47Z1. Find the acute angle between y = 2x + 1 and y = -3x - 2 to the nearest degree.2.Find the acute angle between 3x - 2y + 7 = 0 and 2y + 4x - 3 = 0 to the nearest degree. 3. Find the acute angle between y = x + 3 and y = -3x + 5 to the nearest degreehelp me please!an nhttps://au.mathworks.com/matlabcentral/profile/authors/19672209tag:au.mathworks.com,2005:Question/2756072016-03-27T00:11:04Z2020-09-23T13:32:27ZHow do I get the workspace window back?Suddenly my workspace window has disappeared. How do I get it back? It is usually in the top right of the screen. My programming/editing, command and "files" windows are still fine, but I need to see my workspace, anybody know how to do this? Helen Kirbyhttps://au.mathworks.com/matlabcentral/profile/authors/5494713tag:au.mathworks.com,2005:Question/3132042016-11-21T06:15:32Z2020-09-23T13:32:07ZFeature Request: Refactoring toolI would like to have a real refactoring tool for MATLAB like the one e.g. in PyCharm.
At the moment I'm using Grep if I'm renaming a Class/Method/Function.Nils Ghttps://au.mathworks.com/matlabcentral/profile/authors/5316883tag:au.mathworks.com,2005:Question/5985252020-09-23T13:28:50Z2020-09-23T13:32:01Zgetting an empty figure for line plot of sine functionI'm trying to plot a sine function but I'm getting an empty figure
x=-10:10;
y = (sin(sin(pi*x))) / (pi*x);
zf(1) = figure(1);
za = axes;
zp = plot(x,y);
set(zp(1),'color','m','linewidth',3,'linestyle','-');Maria Gallehttps://au.mathworks.com/matlabcentral/profile/authors/8835633tag:au.mathworks.com,2005:Question/5978802020-09-22T12:09:28Z2020-09-23T13:31:47ZState vector PWM on FPGAI wanted to develop PWM pulses using Space Vector-Pulse Width Modulation and simulate it simulink and further generate a code in HDL for the same.The desired frequency is 25Khz with voltages from +3.3v to -3.3v.Requesting help with the same..Regards,John Doehttps://au.mathworks.com/matlabcentral/profile/authors/19632719tag:au.mathworks.com,2005:Question/5984442020-09-23T10:34:53Z2020-09-23T13:31:39ZHow exactly is the first vertex of a patch in surf determined?In the documentation for the surf command it is stated that for faceColor = 'flat', "The color value at the first vertex of each face (in the positive x and y directions) determines the color for the entire face."
Paired with the accomanying drawing, I completely understand how this work for a rectangular grid. However, I would like to know what exactly is the 'first vertex' in case of a non-rectangular grid. I'm trying to make a polar plot with surf, and this is vital information.
PS, I tried to find out through the source of surf, but it seems like the magic happens in a .p file.
Thank youTim M.J. Nijssenhttps://au.mathworks.com/matlabcentral/profile/authors/10994236tag:au.mathworks.com,2005:Question/5983692020-09-23T08:45:34Z2020-09-23T13:30:15ZHow to change date in a website pageHi all,
I have a problem: I need to change the "Date Range" in this webpage https://markets.ft.com/data/funds/tearsheet/historical?s=LU0546918409:EUR and than read the code using "webread" function:
As you can see, the standard range when the web is opening is the last 30 days, and I would like to change it. I tried with this code:
temp = webread('https://markets.ft.com/data/funds/tearsheet/historical?s=LU0546918409:EUR');
temp2 = strrep(temp,'2020/08/24','2020/07/24')
but i don't know how to reload the webpage with the new html code and date range. Someone can help me? Thanks!Adrianohttps://au.mathworks.com/matlabcentral/profile/authors/5461029tag:au.mathworks.com,2005:Question/5921502020-09-11T10:11:17Z2020-09-23T13:29:02ZSelect area in picture and send information about r,g,bHello,
I need to select an area on my picture and i want to have informations about r,g,b.
Someone can help me, please ?
Thanks!Abbass SAYEGHhttps://au.mathworks.com/matlabcentral/profile/authors/18576860tag:au.mathworks.com,2005:Question/5985222020-09-23T13:26:17Z2020-09-23T13:26:17Z??? Undefined command/function 'somma_init'.I'm trying to create a DLL with Visual Studio, and then i'd like to use it in Matlab using the "loadlibrary('xxx.dll','xxx.h')".
The Dll seems correctly compiled in Visual Studio, and when i use the loadlibrary of Matlab, on the "command windows" nothing error appear.
But, when i call the function defined in the Dll, the error "??? Undefined command/function 'somma_init'.", has shown
Can you help me about this point?, I can share the code of Dll written in Visual studio.
thanks.Giampaolo MOPAhttps://au.mathworks.com/matlabcentral/profile/authors/17142147tag:au.mathworks.com,2005:Question/5983962020-09-23T09:42:31Z2020-09-23T13:26:10ZReshape a multidimensional matrixi have a multidimensional matrix (146x146x144) that i want to reshape (144x21316). the command reshape works "vertically", how i can reshape "horizontally" ( every rows next to another)elena galvanohttps://au.mathworks.com/matlabcentral/profile/authors/13726172tag:au.mathworks.com,2005:Question/5985162020-09-23T13:20:44Z2020-09-23T13:24:18ZMask Creation on an MRI ImageHello to everyone,
I have an image of the size 128*128, and it is a brain MRI image.
The brain is in the middle of the image and around the brain, there are very small values that I want to set them to zero, so that I can have just the brain area in a black background with surrounding pixels of the value 0, in other words: black. Because I will have to do this with lots of other images too i have to come up with a function.
Therefore I coded an algorithm that extracts a brain mask that I can multiply with the orginal image to just get the brain out. This does work fine, but it's not good enough. So I came up with this new idea that I take a default shape that's similar to the brain structure, and I get it to move around in the orginal image as long as the mean signal in that surface gets a maximum value, this would mean in another words that the shape has aligned itself with the brain, so it will have the maximum mean of signal(or sum of the signals of every pixel).
I can't think of anyway to implement this in code. Can someone help me with this problem? or maybe someone has another better idea to extract a mask from different brain structures similar to my problem.
Thanks alot for any tips.
RF.KS
Aref Kalantarihttps://au.mathworks.com/matlabcentral/profile/authors/13151940tag:au.mathworks.com,2005:Question/5979702020-09-22T14:44:32Z2020-09-23T13:17:22ZUsing an IF-else statement based on whether the number of files in a directory are equalHiya,
I am looking to create some code that will look through my file directory and calculate how many .ctr files are present in each subfolder. Then, if the number of .ctr files in each subfolder are equal, the code will run. If not however, then the code will read an error message. I feel like this should be an IF - else statement, but I am not sure. I have some working code that will caluclate the number of files in a directory. I do not know how to do the next step however.
animals = {'List animal filenames'};
for an = 1:length(animals)
prefix = animals{an};
cd(['FILEPATHWAY',prefix,'\ctr\'])
a = dir('*.ctr');
n = numel(a)
end
ThanksRufusShttps://au.mathworks.com/matlabcentral/profile/authors/18269830tag:au.mathworks.com,2005:Question/5970522020-09-21T04:01:24Z2020-09-23T13:17:17ZError Code opening MATLABHello, I get an error code everytime I try to open MATLAB on my computer. I've tried uninstalling and reinstalling multiple times but it hasn't helped. You can email me at justinneillynch@gmail.com
Thank you!Justin Lynchhttps://au.mathworks.com/matlabcentral/profile/authors/19287007tag:au.mathworks.com,2005:Question/5985132020-09-23T13:15:50Z2020-09-23T13:15:50ZError using cross validation with plsregressHi everyone,
I am running a PLS regression and try to perform cross validation (k-fold) with matlab data.
load spectra
X = NIR;
y = octane;
[XL,yl,XS,YS,beta,PCTVAR,MSE] = plsregress(X,y,10,'CV',10);
Unfortunately, this error appear:
Could you explain to me how to solve it please?
Thank you in advance for your help.
Brunobruno ebelhttps://au.mathworks.com/matlabcentral/profile/authors/9069170tag:au.mathworks.com,2005:Question/5985012020-09-23T12:38:10Z2020-09-23T13:12:57ZVelocity signal from accelerometer and the integration using cumtrapzHi,
I have one question regarding the integration of the acceleration signal to obtain the velocity. If we consider a reciprocal motion and since the velocity and acceleration get reset at each cycle, would it be correct to use the cumulative integration cumtrapz MATLAB command for the whole period of acquired data? I think in this case we need to employ the cumtrapz for each loop or cycle separately, correct? But also I should mention that recognizing the cycles for an acceleramoter signal is so hard, there are a huge bunch of signals together being picked from the accelerometer!
Any answer is really appreciated,
Looking forward to hearing the help very soon,
RasoolRasool Mazruee Sebdanihttps://au.mathworks.com/matlabcentral/profile/authors/8138345tag:au.mathworks.com,2005:Question/5946492020-09-16T10:56:34Z2020-09-23T13:09:34ZAggregate multiple CSV files as an average for each cell individually and result in one CSV file with different rows in each source file.Dear all,
Is it possible to take an average based on the rows number of multiple CSV files (3,4,5 ..n number of CSV files) for each cell individually in a new CSV file with the same variables' names and structures. , please?
The files are in one folder, for instance, E:\test\
The number of files is changeable, so, maybe 2 or 3 ... n number of csv files.
The number of columns and rows is also changing but all the files have the same numbers of columns with different number of rows at calculation time, i.e. file test1.csv, test2.csv, and test3.csv, has 3 columns and different rows. When the number of columns is changed, all the columns in the files will be change for example 13 or 15 column. The rows are different in each file.
So, the numbers of columns are changable but it is same numbers for each file and the number of rows are different.
For example, if we have the following data as shown in the pictures:
and the rsult will be as the following picture:
So, in the resulting picture, the average of the first two rows (#0 and #1) is divided by 3 because these two rows are existing in all the source files. The average of the second two rows (#2 and #3) is divided by 2 because these two rows are existing only in two of the source's files. The last two rows (#4 and #5) are divided by 1 because only one source has these two rows.
I have got this Code thankfully from Mr. Asad (Mehrzad) Khoddamfor, which solve my question in the link, which the columns and the rows should be same in the source files.
https://www.mathworks.com/matlabcentral/answers/587366-aggregate-multiple-csv-files-as-an-average-for-each-cell-individually-and-result-in-one-csv-file?s_tid=srchtitle
The code is:
%
% read folder
%
files = ls ('d:\test\*.csv');
for i = 1: size(files, 1)
file = strtrim(files(i,:));
m = readmatrix(['d:\test\' file]);
for r = 1:size(m,1)
if all(isnan(m(r,:)))
m= m(1:r-1,2:end);
break;
end
end
for r = 2:size(m,2)
if all(isnan(m(:,r)))
m= m(1:end,1:r-1);
break;
end
end
if all(isnan(m(:,1)))
m= m(:,2:end);
end
%m
if i==1
mp = zeros(size(m,1), size(m,2), size(files,1));
tb = readtable(['d:\test\' file]);
end
mp(:,:,i) = m;
end
tb(:,2:end) = num2cell(mean(mp,3));
%
% write table, using tblwrite
%
The source files are attached.
Respectfully Yours,
Sherwansherwan Najmhttps://au.mathworks.com/matlabcentral/profile/authors/12230532tag:au.mathworks.com,2005:Question/4086072018-07-03T15:35:19Z2020-09-23T13:08:26ZEnumeration Code Generation with Embedded Coder (autosar.tlc)Hello,
does anyone have a clue what causes the following error message and how I can overcome this problem? I have a Simulink model that uses the enumeration defined in "State_Car.m"
classdef State_Car < Simulink.IntEnumType
enumeration
PARKEN_BN_NIO(1)
PARKEN_BN_IO(2)
STANDFKT_KUNDE_NICHT_IM_FZG(3)
WOHNEN(5)
PRUEFEN_ANALYSE_DIAGNOSE(7)
FAHRBEREITSCHAFT_HERSTELLEN(8)
FAHREN(10)
FAHRBEREITSCHAFT_BEENDEN(12)
SIGNAl_UNBEFUELLT(15)
end
end
The error message I get during build process is:
### Build procedure for model: 'swc_heat_2017b' aborted due to an error.
The header file of the enumerated type State_Car, should be set to Rte_Type.h. To fix this error, update the getHeaderFile method of the enumeration type to return Rte_Type.h
Yu Zhaohttps://au.mathworks.com/matlabcentral/profile/authors/6896899tag:au.mathworks.com,2005:Question/3071642016-10-13T04:00:00Z2020-09-23T13:07:05ZWhy do I receive an Error regarding third party software when Downloading or Installing a support package?Why do I get an Error regarding third party software when Downloading or Installing a support package?
MathWorks Support Teamhttps://au.mathworks.com/matlabcentral/profile/authors/4622813tag:au.mathworks.com,2005:Question/3886522018-03-16T03:07:53Z2020-09-23T13:06:18Zhow to plot fourier series in matlab how to plot fourier series in matlab omar alblooshihttps://au.mathworks.com/matlabcentral/profile/authors/12404352tag:au.mathworks.com,2005:Question/5970582020-09-21T04:19:53Z2020-09-23T13:03:47ZError starting desktop for R2016a-Windows 10I really need help with this issue, I tried with many versions but still i get the same problemSaad Alharbihttps://au.mathworks.com/matlabcentral/profile/authors/19417415tag:au.mathworks.com,2005:Question/5985042020-09-23T12:41:03Z2020-09-23T13:02:00ZHow can I display the sum of the digits of a number entered by a user?I am new to MATLAB, and I want to know how can I display the sum of the digits of a number entered by a user, I started the program but I got stuck.
x=input('Please enter a number: '); %asks the user to enter a number
n= strlength(abs(x) + "") %count the number of digits in that number
y=fprintf('The number of digits of %d is %d \n',x,n);
I would appreciate it if anyone could help. Thank you in advance.
Rodha Mhttps://au.mathworks.com/matlabcentral/profile/authors/19431637tag:au.mathworks.com,2005:Question/5958102020-09-18T07:23:07Z2020-09-23T13:00:15Z Index exceeds the number of array elements (1).Can anybody please help why I am getting this error. I am unable to figure out what I am doing wrong in this code.
clear all; close all; clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Simulation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%value of constants
a=0.1;
omega=5;
dt=0.01;%step size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x(1)=1;
y(1)=1;
for i=2:1000
x(i)=x(i-1)+((a-x(i-1)^2-y(i-1)^2)*x(i-1)-omega*y(i-1))*dt;
y(i)=y(i-1)+((a-x(i-1)^2-y(i-1)^2)*y(i-1)+omega*x(i-1))*dt;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Observation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ndatamin=4;Ndatamax=16;
Data=Ndatamin:1:Ndatamax;
Data=Data/Ndatamax;
PE_x=zeros([1,Ndatamax-Ndatamin+1]);%initialization
count=0;
for N_m=Ndatamin:Ndatamax
count=count+1;
N_measurements=N_m;
N_basis=16;
index=randi([2,999],1,N_m);
Xdot=zeros([1,N_measurements]);
for ni=1:N_measurements
Xdot(ni)=(x(index(ni)+1)-x(index(ni)))/dt;
end
M=zeros([N_measurements,N_basis]);
for i=1:N_measurements
for j=1:N_basis
if j==1
M(i,j)=1;
elseif j==2
M(i,j)=x(index(i));
elseif j==3
M(i,j)=y(index(i));
elseif j==4
M(i,j)=x(index(i))*y(index(i));
elseif j==5
M(i,j)=x(index(i))^2;
elseif j==6
M(i,j)=y(index(i))^2;
elseif j==7
M(i,j)=x(index(i))^2*y(index(i))^2;
elseif j==8
M(i,j)=x(index(i))^2*y(index(i));
elseif j==9
M(i,j)=x(index(i))*y(index(i))^2;
elseif j==10
M(i,j)=x(index(i))^3;
elseif j==11
M(i,j)=y(index(i))^3;
elseif j==12
M(i,j)=x(index(i))^3*y(index(i));
elseif j==13
M(i,j)=x(index(i))*y(index(i))^3;
elseif j==14
M(i,j)=x(index(i))^3*y(index(i))^2;
elseif j==15
M(i,j)=x(index(i))^2*y(index(i))^3;
else
M(i,j)=x(index(i))^3*y(index(i))^3;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% RIP %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Norms=zeros([1,N_basis]);
for j=1:N_basis
Norms(j)=norm(M(:,j));
end
for i=1:N_measurements
for j=1:N_basis
M(i,j)=M(i,j)/Norms(j);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Reconstruction %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lambda=0.001;
Xdot=Xdot';
cd 'E:\MATLAB\bin\cvx\cvx'
cvx_setup
cvx_begin
variable ksaix(16);
minimize(norm(M*ksaix-Xdot)+ lambda*norm(ksaix,1));
cvx_end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% RIP %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for j=1:N_basis
ksaix(j)=ksaix(j)/Norms(j);
end
ksaix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%value of constants
c2=a;
c3= -omega;
c9= -1;
c10= -1;
x_rec(1)=x(1);
y_rec(1)=y(1);
%value of constants
d1=ksaix(1);
d2=ksaix(2);
d3=ksaix(3);
d4=ksaix(4);
d5=ksaix(5);
d6=ksaix(6);
d7=ksaix(7);
d8=ksaix(8);
d9=ksaix(9);
d10=ksaix(10);
d11=ksaix(11);
d12=ksaix(12);
d13=ksaix(13);
d14=ksaix(14);
d15=ksaix(15);
d16=ksaix(16);
PE_x(count)=0;%initialization
Norm_x=0;%initialization
for i=2:1000
xhat(i)= d1+d2*x_rec(i-1)+d3*y_rec(i-1)+d4*x_rec(i-1)*y_rec(i-1)+d5*x_rec(i-1)^2+d6*y_rec(i-1)^2+d7*x_rec(i-1)^2*y_rec(i-1)^2+d8*x_rec(i-1)^2*y_rec(i-1)+d9*x_rec(i-1)*y_rec(i-1)^2+d10*x_rec(i-1)^3+d11*y_rec(i-1)^3+d12*x_rec(i-1)^3*y_rec(i-1)+d13*x_rec(i-1)*y_rec(i-1)^3+d14*x_rec(i-1)^3*y_rec(i-1)^2+d15*x_rec(i-1)^2*y_rec(i-1)^3+d16*x_rec(i-1)^3*y_rec(i-1)^3;
end
PE_x(count)=PE_x(count)+(xhat(i)-x(i))^2;
Norm_x= Norm_x+x(i)^2;
PE_x(count)=sqrt(PE_x(count))/sqrt(Norm_x);
end
figure
hold on
plot (Data,PE_x,'s-r')
I am getting this error [ndex exceeds the number of array elements (1).
Error in trial (line 132)
xhat(i)= d1+d2*x_rec(i-1)+d3*y_rec(i-1)+d4*x_rec(i-1)*y_rec(i-1)+d5*x_rec(i-1)^2+d6*y_rec(i-1)^2+d7*x_rec(i-1)^2*y_rec(i-1)^2+d8*x_rec(i-1)^2*y_rec(i-1)+d9*x_rec(i-1)*y_rec(i-1)^2+d10*x_rec(i-1)^3+d11*y_rec(i-1)^3+d12*x_rec(i-1)^3*y_rec(i-1)+d13*x_rec(i-1)*y_rec(i-1)^3+d14*x_rec(i-1)^3*y_rec(i-1)^2+d15*x_rec(i-1)^2*y_rec(i-1)^3+d16*x_rec(i-1)^3*y_rec(i-1)^3;
>> ]Heya :)https://au.mathworks.com/matlabcentral/profile/authors/9179792tag:au.mathworks.com,2005:Question/2638332016-01-14T23:09:19Z2020-09-23T12:59:04ZLinux Hot Key SettingsOn Linux Ubuntu 14.04, MATLAB uses the weirdest hot key combinations I've ever seen by default. For example, to copy is *'Alt+W'* and paste is *'Ctrl+Y'*. I want the standard *'Ctrl+C'* and *'Ctrl+V'* combinations. How do I control this?Richardhttps://au.mathworks.com/matlabcentral/profile/authors/4467800tag:au.mathworks.com,2005:Question/5984412020-09-23T10:34:38Z2020-09-23T12:58:34ZHow to have array in for loopHi,
So I have a matrix and I want to divide some columns by other columns in a for loop, because I want to divide sets of 3 columns by different sets, so i have created this example:
one=1:24;
two= 25:48;
three=49:72;
four=73:96;
M=[one;two;three;four]
for i=1:4
for j=1:3
Mnew(i,j)=M(i,j)./M(i,16:18);
end
for j=4:6
Mnew(i,j)=M(i,j)./M(i,19:21);
end
end
How can I make j=1:3 literally an array such as 16:18, because now it won't let me run this.matlabberhttps://au.mathworks.com/matlabcentral/profile/authors/7404740tag:au.mathworks.com,2005:Question/5922312020-09-11T13:19:58Z2020-09-23T12:54:46ZExport a plane in 3D coordinate as a surface mesh (STL file)I have four points in 3D space which are coplanar. I want to export the plane created by these 4 points as a STL file. I have tried to use "delaunayTriangulation" function as follow
x = [-86.0789; -98.9967; -96.7493; -88.3263];
y = [-67.3229; -82.9531; -72.5115; -77.7645];
z = [45.9099; 23.8005; 35.4591; 34.2513];
tri = delaunayTriangulation(x,y,z);
stlwrite(tri,'plane.stl');
However I get a warning stating that "The triangulation is empty - the points may be coplanar or collinear." and the "tri" variable is empty. Do you have any suggestions for exporting such a plane in 3D space as a STL file?
Could it be due to the reason that the triangulation does not fit in the Delaunay triangulation criterion as mentioned here? if it is the case, how can I sample more points such that I can garantee that they would fit in the critetion and can export the plane as surface mesh?Torkan Gholamalizadehhttps://au.mathworks.com/matlabcentral/profile/authors/14467167tag:au.mathworks.com,2005:Question/5983722020-09-23T08:50:03Z2020-09-23T12:54:17Zhow to describe the nth term of convolution in matlabhow I can describe , I need this code in the applicatin of differential transformation methodWasim Abbashttps://au.mathworks.com/matlabcentral/profile/authors/13878212tag:au.mathworks.com,2005:Question/5981892020-09-22T22:00:09Z2020-09-23T12:54:09ZHow to export the data corresponding to the new pixel size?Hi,
I have image data with 100*100 (pixel x pixel) and the pixel size is 10. Each pixel has a resulted value e.g., temperature
Now I would like to change the pixel size to 5 and still keep the same size of the image.
I wonder how to get the new image data (X, Y, and temperature) corresponding to the pixel size 5.
I really appreciate your help.
ThanksFrancescohttps://au.mathworks.com/matlabcentral/profile/authors/727750tag:au.mathworks.com,2005:Question/5985072020-09-23T12:52:50Z2020-09-23T12:53:23ZOptimization of AlexNet using Genetic Algorithm Can I optimize AlexNet architecture with the help of Genetic Algorithm?
If yes.. Please give me some idea about the procedure for optimizing AlexNet....
Thanx Alot in advance.priyanka jindalhttps://au.mathworks.com/matlabcentral/profile/authors/13795513tag:au.mathworks.com,2005:Question/4581342019-04-24T05:44:13Z2020-09-23T12:53:05ZError Starting Desktop (java.lang.NullPointerException)-WIN10-Matlab R2019a
I just installed Matlab_R2019a on Windows 10 and I'm getting the error below on startup.
I have changed my user account in my computer and just used the alphabets and reinstalled my matlab but the issue persists. What should I do ?
yunjie dinghttps://au.mathworks.com/matlabcentral/profile/authors/13141247tag:au.mathworks.com,2005:Question/5969532020-09-20T19:00:45Z2020-09-23T12:49:20Zhow can i save the data after processing sequence of images?i have a lot of images, for example 0001,0002.....10000, after processing the result data will be in .dat file it is just getting overwritten and finally i get only 10000 image data. can anyone help me from this?
clearvars, close all
clc
myFolder = '';
filePattern = fullfile(myFolder, '*.jpg'); % my images are in subfolders, so i changed your filepattern
jpegFiles = dir(filePattern);
% For simplicity of this example, lets use the full/absolute path to the images
fileNameCell = fullfile({jpegFiles.folder}, {jpegFiles.name});
% Call the function with cellfun; returns a cell with each entry corresponing to the fileNameCell
meanbottomlineCell = cellfun(@findmeanbottomline, fileNameCell);
function meanbottomLine = findmeanbottomline(img_fullfile)
img = imread(img_fullfile);
[rows, columns, numberOfColorChannels] = size(img);
if numberOfColorChannels > 1
grayImage = rgb2gray(img);
else
grayImage = img;
end
highThreshold = 210;
binaryImage = grayImage <= highThreshold;
binaryImage = bwareafilt(binaryImage, 1);
binaryImage = imfill(binaryImage, 'holes');
bottomLine = zeros(rows, 1);
for col = 1 : columns
thisColumn = binaryImage(:, col);
lastLine = find(thisColumn, 1, 'last');
if ~isempty(lastLine)
bottomLine(col) = lastLine;
end
end
meanbottomLine = mean(bottomLine(bottomLine>0));
% Put red line there at that level.
hold on;
line([1, columns], [meanbottomLine, meanbottomLine], 'Color', 'r', 'LineWidth', 2);
caption = sprintf('Cleaned Binary Image with last line at an average of %.1f', meanbottomLine);
save 123.dat meanbottomLine -ascii
endbasha Shaikhttps://au.mathworks.com/matlabcentral/profile/authors/17371496tag:au.mathworks.com,2005:Question/5971152020-09-21T07:11:51Z2020-09-23T12:47:06ZSimulink Onramp Error enableAddon.mHello,
I have a problem with the installation of Simulink Onramp.
The following error occurs after I clicked on the "Simulink Onramp" button:
Can anybody help me? What's the reason for the error?
Best regardsAlexander Hupferhttps://au.mathworks.com/matlabcentral/profile/authors/19592340tag:au.mathworks.com,2005:Question/5984952020-09-23T12:27:22Z2020-09-23T12:46:51Zconvert a 3D matrix to a 2D matrix Hello,
I'm trying to convert a A by B by C matrix (3D) into a A*C by B matrix (2D). But I need the column (with A*C elements) to be not stacked, but alternated. To explain,
I would like to convert a 2 by 2 by 3 matrix X:
val(:,:,1) =
1 2
1 2
val(:,:,2) =
2 3
2 3
val(:,:,3) =
3 4
3 4
into 2*3 by 2 matrix:
[1 2
2 3
3 4
1 2
2 3
3 4]
I have tried:
X1=permute(X,[1 3 2]);
X2=reshape(X1,[6,2]);
but it generates:
X2 =
1 2
1 2
2 3
2 3
3 4
3 4
which is NOT what I want.
Is there a way to do this? Any advice appreciated!Ara Johttps://au.mathworks.com/matlabcentral/profile/authors/18994283tag:au.mathworks.com,2005:Question/2383712015-08-31T14:38:48Z2020-09-23T12:46:07ZError Starting Desktop (java.lang.NullPointerException)I just installed Matlab_R2014a on OS X 10.10 and I'm getting the error below on startup. I've tried updating the java installed but the issue persists. In the installation I accepted every toolbox (as I don't know which ones we'll be heading).
<</matlabcentral/answers/uploaded_files/36432/Screen%20Shot%202015-08-31%20at%2016.34.10.png>>
Zeerak Waseemhttps://au.mathworks.com/matlabcentral/profile/authors/3964243tag:au.mathworks.com,2005:Question/5984322020-09-23T10:22:53Z2020-09-23T12:45:43ZHow can i connect these points that is basically act as transmitter and receiver. To connect one X with * individually
x_r = xx;
y_r = yy;
for i = 1 : length(x_r)
x_r(i) = x_r(i) + 35*rand();
end
for i = 1 : length(y_r)
y_r(i) = y_r(i) + 35*rand();
end
scatter(xx,yy,'X'); %Transmitter denoted by X
xlabel('x');
ylabel('y');
axis square;
hold on;
scatter(x_r,y_r,'*','r') %Receiver denoted by Red *
xlabel('x');
ylabel('y');
axis square;
Alex Carryhttps://au.mathworks.com/matlabcentral/profile/authors/19669556tag:au.mathworks.com,2005:Question/5984262020-09-23T10:19:06Z2020-09-23T12:45:21ZPlot data from text fileI want to plot ReP^2+ImP^2 as function of numero = 5, 10, 15 …145 for each mode(m,n) I would like to have something like this with the name of the mode on each curve. Here is the beginning of my code, anyone can help ?
data = readfile(test.txt)
HeaderLines = 8;
for i=(HeaderLines+1):numel(tm)
%store in temp variable
if isempty(data{i}),continue,end
str=data{i};
line = str2num(str);
....
You can find my file attached.
Thank you in advance,Izemhttps://au.mathworks.com/matlabcentral/profile/authors/13522793tag:au.mathworks.com,2005:Question/5969622020-09-20T20:18:58Z2020-09-23T12:44:42ZHow to align two images from different sources?Hi!
I am working on a project to fuse two images, RGB + Infrared (1 Channel). I noticed the images from RGB source has a slightly wider angle than IR source. Both image souces have different resolution as well. RGB 1800x1600pixels, whereas IR source 640x512 pixels. I have tried to manually crop and then feed new image into fusion algorithm, but I would not consider my croping to be as good. Is there an optimal way to align two images, so that they can be fed into an algorithm?
RGB image: https://imgur.com/PUMY2ap
IR image: https://imgur.com/bOmhlcYKevhttps://au.mathworks.com/matlabcentral/profile/authors/4323166tag:au.mathworks.com,2005:Question/5984802020-09-23T11:46:57Z2020-09-23T12:43:33ZHow can I replace the high pass filter with a Bandpass filter? (New to matlab)fontSize = 22;
K = csvread("HeartBeatSample.csv") %path to the sample file
Time = K(1:45465,1);
Voltage= K(1:45465,2); %/amplitude
plot(Time,Voltage) % Plotting the virtual data that given
J = fir1(1000,1/1000*2,'high'); % Smoothing using high pass filter
Voltage_filter = filter(J,1,Voltage);
plot(Voltage_filter)
Findsq = Voltage_filter.^2;
plot(Findsq);
last = 0;
Point = 0;
pulse = zeros(length(Findsq),1);
for L = 1:length(Findsq)
p = 0;
if (Findsq(L) > 0.8)
if (Point == 0)
if (last > 0)
t = L - last;
p = 1000/t*60;
end
last = L;
end
Point = 100;
else
if (Point > 0)
Point = Point - 1;
end
end
pulse(L)=p;
end
plot(pulse); % plotting the pulse graph
grid on;
title('Pulse', 'FontSize', fontSize, 'Interpreter', 'none');
%xlabel('Numbers Of Data');
ylabel('BPM')
title('BPM Graph');
y = pulse;
x = 1 : length(y);
% There are a large number of zeros. Let's set those to nan to ignore them
badIndexes = y <= 0;
% Get rid of those.
x(badIndexes) = [];
y(badIndexes) = [];
% Plot them in red.
hold on;
plot(x, y, 'r-', 'LineWidth', 2);
grid on;
% Find the min and put a line there.
darkGreen = [0, 0.7, 0];
yline(min(y), 'Color', darkGreen, 'LineWidth', 2);
caption = sprintf('Pulse. Min = %f, max = %f', min(y), max(y));
title(caption, 'FontSize', fontSize, 'Interpreter', 'none');
yPrior = rand(1); % Initialize
for L = 1 : length(y)
if ~isnan(y(L)) && y(L) ~= yPrior
if y(L) < 80
fprintf("You're in Normal condition at L = %d with a pulse of %f.\n", x(L), y(L));
elseif y(L) <= 90
fprintf("You're in Stressed condition at L = %d with a pulse of %f.\n", x(L), y(L));
else
fprintf("You're in Critical condition at L = %d with a pulse of %f.\n", x(L), y(L));
end
end
yPrior = y(L);
end
g = gcf;
g.WindowState = 'maximized'
MATLAB Version 9.8 (R2020a)
Simulink Version 10.1 (R2020a)
Control System Toolbox Version 10.8 (R2020a)
DSP System Toolbox Version 9.10 (R2020a)
Data Acquisition Toolbox Version 4.1 (R2020a)
Signal Processing Toolbox Version 8.4 (R2020a)
Statistics and Machine Learning Toolbox Version 11.7 (R2020a)
Symbolic Math Toolbox Version 8.5 (R2020a)Salinda Nandasena Talapitiya Rallagehttps://au.mathworks.com/matlabcentral/profile/authors/18992370tag:au.mathworks.com,2005:Question/5983032020-09-23T04:10:48Z2020-09-23T12:40:37ZHow to write a video from png files and/or matlab figuresHello,
I've been trying to write a simple code that takes a sequence of images and makes a video from them. However, the video file always ends up empty or unreadable, and I have no idea why the code isn't working. This is the code :
video23 = VideoWriter('video23.avi', 'Archival');
%video23.FrameRate = 1;
open(video23);
baseN = 'VectorOverlay';
d = '_';
e = 'Individual.png';
f = '-';
for i = 1:87
file_name = [baseN,d,num2str(i),f,num2str(i+1),d,e];
%VectorOverlay_1-2_Individual.png from PIV analysis
im = imread(file_name);
figure(1)
image(im)
writeVideo(video23, im);
end
close(video23)
implay(video23);
Can someone help me? I also have the images saved as Matlab figures, but matlab won't recognize the file format when I try and get it to read the files. Anna Clouvel-Gervaiseauhttps://au.mathworks.com/matlabcentral/profile/authors/11464198tag:au.mathworks.com,2005:Question/2393802015-09-03T08:39:40Z2020-09-23T12:35:59Zpitch shift of speechHello
i am new to matlab and i just want to change voice by pitch shift or by any other method.
Thanksusman siddiqhttps://au.mathworks.com/matlabcentral/profile/authors/6824991tag:au.mathworks.com,2005:Question/1124032014-01-15T00:15:20Z2020-09-23T12:33:55ZHow do I replace [ ] in an array with 0's <</matlabcentral/answers/uploaded_files/6842/pathrisk.JPG>>
How can i replace the [] in the pathrisk field with 0's?
Thanks for your help!Kenneth Morleyhttps://au.mathworks.com/matlabcentral/profile/authors/4800124tag:au.mathworks.com,2005:Question/5984592020-09-23T11:05:55Z2020-09-23T12:32:32Zhow can I plot 800 samples in a percentage cicle from 0 to 100% on x axis?sara notarnicolahttps://au.mathworks.com/matlabcentral/profile/authors/9388399tag:au.mathworks.com,2005:Question/5978292020-09-22T11:07:27Z2020-09-23T12:32:07ZConvert Data from arrayHi
I have attached a Jpeg of my data file displayed in a plot,(0 to 80mS) it shows exactly the data I need how do I convert this data to a new array as is in the plot. The actual array use to create the plot has 16000 samples at 5uS per sample which is of no interest .I just need the 1s and 0s as the plot along with there timing and not 16000 1s and 0s
Thank you for any help
DavidDavid Joneshttps://au.mathworks.com/matlabcentral/profile/authors/14266637