https://ww2.mathworks.cn/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2019-02-20T19:50:10Ztag:ww2.mathworks.cn,2005:Question/4461052019-02-20T19:41:55Z2019-02-20T19:50:10ZHow to find max and min of fuction of 2 independent variables?My question is how can I find minimum and maximum of this function, and then tag them with 'o' in function graph?
This is my code so far:
function funkcija(intervalpox,intervalpoy,korak,crtanje)
x=0:korak:intervalpox;
y=0:korak:intervalpoy;
[X,Y] = meshgrid(x,y);
Z = (sin(sqrt(X.^2 + Y.^2)) ./ (sqrt(X.^2 + Y.^2)));
mesh(X,Y,Z)
grid on
xlabel('.x.')
ylabel('.y.')
zlabel('.z.')
title('mesh')Faris Hajdarpasichttps://ww2.mathworks.cn/matlabcentral/profile/authors/14824638-faris-hajdarpasictag:ww2.mathworks.cn,2005:Question/4461002019-02-20T19:24:02Z2019-02-20T19:48:40ZUser Input - Max and min temperature I am trying to resolve an exercice. I need to:
Create diario_temp;
Save diario_temp in temperaturas.mat
User input: Temperature min
User input: Temperature max
Verify if Temperature max is superior than temperature min
Then, shown hours of the day than is superior than user input: Temperature min and inferior than user input: Temperature max
I am having an hard time, if you have any suggestion I will apreciated.
% Criação do ficheiro temperaturas.mat
diario_temp=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23;7.2 7.0 6.77 6.2 6 4.9 4.5 4.7 5.1 7.3 8.5 12.1 13.9 14.2 15.1 16 14.1 12.2 11.4 10.5 9.5 8.7 7.2 6.1];
save('temperaturas.mat','diario_temp')
% Perguntar ao utilizador a temperatura mínima
TempMin = input('Qual a temperatura mínima? ', 's');
disp(['Temperatura mínima: ', TempMin]);
% Perguntar ao utilizador a temperatura máxima
TempMax = input('Qual a temperatura máxima? ', 's');
disp(['Temperatura máxima: ', TempMax]);
% Verificar condição Temperatura máxima >= Temperatura mínima
if((TempMax) >= (TempMin))
% load('temperaturas.mat')
% idx=find(diario_temp > 5)
% value=diario_temp(idx)
% whos -file temperaturas.mat
else((TempMax) <= (TempMin));
disp('A Temperatura Máxima é menor que a Temperatura Mínima !!!')
endMickael Diashttps://ww2.mathworks.cn/matlabcentral/profile/authors/8725817-mickael-diastag:ww2.mathworks.cn,2005:Question/4461062019-02-20T19:48:13Z2019-02-20T19:48:13ZUsing imrotate creates empty arrayI am attempting to use imrotate to rotate an array by a given amount of degrees, but the output is all zeros.
I = rgb2ycbcr(RBG);
I = imrotate(I, angle, 'crop');
Where RBG is nx3 uint8 RGB variable from an .avi file from Vevo Software.
Jamie Bossenbroekhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14610145-jamie-bossenbroektag:ww2.mathworks.cn,2005:Question/4460762019-02-20T16:54:50Z2019-02-20T19:41:04ZI keep getting the error "subscript must either be real positive integers or logicals" even when I place an 'if' statementIt seems I keep getting the error "subscript must either be real positive integers or logicals".
This must be because I have started of from i = 1, hence i - 1 = 0 and thats where the problem is. I thought that my ' if ' loop would have solved that issue, but it does not seem to be working.
Thank you,
My script is below:
U=1
S = 1.7*1.2*ones(1, 10);
Tout = 5
ma = 1
ca = 2
DTM = 1
deltat = 1
index = 1:30;
%Prealloacate
SQAmb = zeros(numel(index), numel(S));
QAmb_Total = zeros(size(index));
deltaTin = zeros(size(index));
Tin = zeros(size(index));
%for loop
for i = index
if (i)==1
Tin(i) = 20
else
Tin(i) = Tin(i-1)+deltaTin(i)
end
SQAmb(i,:) = S*U*(Tout-Tin(i));
%Total Ambient Load in Array Form
QAmb_Total(i) = sum(SQAmb(i,:))
%change in air cabin temperature where deltat is timestep
deltaTin(i) = (QAmb_Total(i)/((ma*ca)+DTM))*(deltat)
%New car cabin temperature
Tin(i) = Tin(i-1)+deltaTin(i)
endJamil Dudhwalahttps://ww2.mathworks.cn/matlabcentral/profile/authors/14547273-jamil-dudhwalatag:ww2.mathworks.cn,2005:Question/4461042019-02-20T19:38:58Z2019-02-20T19:38:58Zcalculate mfcc and pitch coeffientshi everyone
i am using matlab 2015b version. could anybody help me how to calculate pitch and mfcc coefficients . i know in 2018 version of matlab .it has ptich and mfcc command.But as my computer is old. i cant install 64 bit matlab . if you help .i really appreciate.
thank you ali okumushttps://ww2.mathworks.cn/matlabcentral/profile/authors/14179689-ali-okumustag:ww2.mathworks.cn,2005:Question/4461032019-02-20T19:38:49Z2019-02-20T19:38:49ZData Curve Fitting Not Fitting Third Point?Any ideas why it appears the third data point is not being fit?
xdata = [1;10;100];
ydata = [0;0;0.3];
fun = @(x,xdata)(1./(1+(x(1)./xdata).^x(2)));
lb = [1,1];
ub = [1000,5];
x0 = [50,2];
x = lsqcurvefit(fun,x0,xdata,ydata,lb,ub)
figure
hold on
plot(xdata,ydata,'ko');
xlim([0 200]);
xlabel('Concentration','FontWeight','bold');
ylim([0 1]);
ylabel('Average Mortality','FontWeight','bold');
box off
y = 0:200;
plot(1./(1+(x(1)./y)).^x(2))
xlim([0 200])
ylim([0 1])Kelly McGuirehttps://ww2.mathworks.cn/matlabcentral/profile/authors/2733866-kelly-mcguiretag:ww2.mathworks.cn,2005:Question/4460342019-02-20T13:29:58Z2019-02-20T19:36:25ZHow to create a matrix with arbitrary dimensionsHi,
I like to create a matrix with arbitrary dimensions.
E.g., I need a function getMatrix(m, s), which returns a m-dimensional matrix with size s, filled with zeros or ones.
Could not working out until today, help is appreciated.Michael Haitzhttps://ww2.mathworks.cn/matlabcentral/profile/authors/864616-michael-haitztag:ww2.mathworks.cn,2005:Question/4452522019-02-16T02:55:05Z2019-02-20T19:31:41ZCreating plot with 2 x axesI have written the following snippet of code for creating a plot with two x axes
figure(),
x1 = linspace(0,100,101);
y1 = sin(x1);
plot(x1,y1)
xlabel('Loss (%)')
ylabel('Energy Efficiency (%)')
x2 = x1*5*40000/100;
ax1 = gca;
ax1_pos = ax1.Position;
ax2 = axes('Position', ax1_pos, 'XAxisLocation', 'top', 'YAxisLocation', 'right');
plot(x2, y1, 'Parent', ax2);
I have configured the 2nd x axis to be on the top, but I get the following, where the two x axes overlap:
I tried the code in this post: https://www.mathworks.com/help/matlab/creating_plots/graph-with-multiple-x-axes-and-y-axes.html?searchHighlight=two%20x-axes
and the code works. But I don't understand what's the problem with my code. Could anybody explain please?Md. Rahmanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4044690-md-rahmantag:ww2.mathworks.cn,2005:Question/829072013-07-23T12:17:53Z2019-02-20T19:29:20ZCombining matrices of different sizesHi
How can i combine two matrices of different sizes?
e.g,
x = [1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16];
y = [1 2 3;4 5 6;7 8 9];
and
z = [x y]; % where z is also a matrix
how should i combine to x & y to get z?
I tried using the cat function but it gives an error:"Dimensions of matrices being concatenated are not consistent".
Syedhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4419695-syedtag:ww2.mathworks.cn,2005:Question/4459642019-02-20T08:06:30Z2019-02-20T19:28:50ZSaving a file in a folder Hi;
How can I save a file in a folder with a .FIG and .PNG extension in Matlab?
Actually I want to save the file in a folder by writing a Matlab code.
Regards,SEVAL DONERTAShttps://ww2.mathworks.cn/matlabcentral/profile/authors/12769332-seval-donertastag:ww2.mathworks.cn,2005:Question/4460232019-02-20T12:46:13Z2019-02-20T19:27:56ZHow to modify this could so it can read from different files groups?Hi,
I have this code that reads from 10 files each maximum X value and its corresponding Y value and prints all results in one file (named "Result_1, Result_2,...")
Now, I have 400 files. I need to modify the code, so it can read the different groups sequentially and print the output file for each group.
For instance, I need it to read from 1 to 10, then from 11 to 20, then from 21 to 30, and so on until 391 to 400.
Hence, the printed output files are: Result_1 (for files 1 to 10), Result_2 (for files 11 to 20), and so on until the output file Result_40 (for files 391 to 400).
The code:
S = dir('*.out');
C = natsortfiles({S.name});
N = numel(C);
Z = nan(N,1);
for k = 1:N
data = load(C{k});
[~,idx] = max(data(:,1));
Z(k) = data(idx,2);
end
dlmwrite('Result_1.txt',Z)Ismail Qeshtahttps://ww2.mathworks.cn/matlabcentral/profile/authors/10292327-ismail-qeshtatag:ww2.mathworks.cn,2005:Question/4461022019-02-20T19:26:35Z2019-02-20T19:26:35ZHow to delete empty cells in a cell array? I would like to delete all of the empty {0×0 double} cells in each row, then shift the cells that have values in them to the left.
Starting with:
{["laterite-00001"]} {[ 30552]} {[ 227634]} {[ 123220]}
{["laterite-00002"]} {0×0 double} {0×0 double} {[1345]}
{["laterite-00003"]} {0×0 double} {0×0 double} {[443266]}
{["laterite-00004"]} {0×0 double} {0×0 double} {[87887]}
{["laterite-00005"]} {[1323]} {[87455]} {[23345]}
{["laterite-00006"]} {[43233]} {[454547]} {0×0 double}
I would like to end with this:
{["laterite-00001"]} {[30552]} {[227634]} {[123220]}
{["laterite-00002"]} {[1345]}
{["laterite-00003"]} {[443266]}
{["laterite-00004"]} {[87887]}
{["laterite-00005"]} {[1323]} {[87455]} {[23345]}
{["laterite-00006"]} {[43233]} {[454547]}Matthew Tyler Jeffrieshttps://ww2.mathworks.cn/matlabcentral/profile/authors/10690432-matthew-tyler-jeffriestag:ww2.mathworks.cn,2005:Question/4461012019-02-20T19:25:17Z2019-02-20T19:25:17ZI need to solve and plot time, acceleration, velocity, and dsiplacement using a force equation that is in terms of Velocity. I would like to have time as my input and A,V,S as outputs. The changing acceleration causes the real headache. Here is my current code but I dont beleive that it is calculating the way that it should. I am using this to find quarter mile time and speed and 0-60 time .
Power = 125*(10^3); %kW
af = 2.21; %frontal area
m = 1407.497; %mass of the vehicle
rho = 1.225; %density of air
cd = .30; %Coeff of Drag res
cr = .03; %Coeff of roll res
g = 9.81; %gravity
t = 0:.1:40;
v = a.*t
F = (Power./v) - .5*rho*(v.^2)*af*cd - cr*m*g;
a = F/m;
S = v.*t +1/2*a*t.^2;
Jacob Ridenourhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13762761-jacob-ridenourtag:ww2.mathworks.cn,2005:Question/4459332019-02-20T02:46:40Z2019-02-20T19:18:37ZI need help with a material balance problem. FUNCTION:
function [A, B, C, D, E, F] = material_balance (Ao, Bo, Co, Do, Eo, Fo)
[A, B, C, D, E, F] = Ao+Bo+Co+Do+Eo+Fo
k21 =0.2;
k31 =0.1;
k32 =0.1;
k34 =0.1 ;
k54 =0.05;
k64 =0.2 ;
k12 =0.1 ;
k13 =0.05 ;
k23 =0.05;
k43 =0.2 ;
k45 =0.1;
k46 =0.2;
k65 =0.1;
k56 =0.1;
x = [ -(k21+k31) k12 k13 0 0 0
k31 k32 -(k13+k23+k43) k34 0 0
0 0 0 k54 -(k45-k65) k56
k21 -(k12+k32) k23 0 0 0
0 0 k43 -(k34+k54+k64) 0 k45
0 0 0 k64 k65 -(k46+k56)];
b = [0
0
0
0
0
0];
[A B C D E F]= inv(x)*b
SCRIPT:
clear, clc, close all
Ao =1.0;
Bo =0;
Co =0 ;
Do =0 ;
Eo =1.0;
Fo= 0;
[A, B, C, D, E, F] = material_balance (Ao, Bo, Co, Do, Eo, Fo)
Please Help!
Nicole Jacksonhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14489425-nicole-jacksontag:ww2.mathworks.cn,2005:Question/4460962019-02-20T18:29:55Z2019-02-20T19:18:37ZProblem in using xlswrite commandHello All,
I am trying to get the output in excel file but I am unable to do that. I have attached the screen shot of my code along with some information.
here is the output in Excel and I think that the problem is becuase the result is not a scalar number
I will be great if someone please help me with this.
Thank You Ronhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13715360-rontag:ww2.mathworks.cn,2005:Question/2894152016-06-11T16:03:13Z2019-02-20T19:15:54Zfzero Index exceeds matrix dimensions, image processinghi everybody, im processing satelite imagenary, the last step in the process is a nonlinear ecuation so I'm using Fzero but it continues telling me that index exceeds matrix dimensions here is my script.
%%%%cargar imagenes%%%%
IM(:,:,2)=double(geotiffread('LC80280452015160LGN00_B2.TIF'));
RED(:,:,4)=double(geotiffread('LC80280452015160LGN00_B4.TIF'));
%%%%%TOA%%%%%%
%Banda Azul=2
A(:,:,2)=IM(:,:,2)*0.00002;
A1(:,:,2)=A(:,:,2)+0.1;
Atoa(:,:,2)=A1(:,:,2)/0.9279549148;
%banda Roja=4
R(:,:,4)=double(RED(:,:,4)*0.00002);
R1(:,:,4)=R(:,:,4)+0.1;
toar(:,:,4)=R1(:,:,4)/0.9279549148;
figure, imshow(toar(:,:,4))
figure, imshow(Atoa(:,:,2))
%%%%Reflectancia superficie%%%%
ASi(:,:,2)=double(geotiffread('B1.TIF'));
RSi(:,:,4)=double(geotiffread('B3.TIF'));
AS(:,:,2)=ASi(:,:,2)/10000;
RS(:,:,4)=RSi(:,:,4)/10000;
%%%%AOT%%%%
F=@(t)((0.665483767.*(Atoa(:,:,2)-0.091226952-((exp(-1 .*(0.242593401+t(:,:,2))).*exp(-1 .*(0.242593401+t(:,:,2))/0.927954915).*AS(:,:,2))./(1-AS(:,:,2).*(0.92.*0.242593401+(1-0.725681).*t(:,:,2)).*exp(-1 .*(0.242593401+t(:,:,2)))))))-t(:,:,2));
X(:,:,2)=fzero(F,1);
%%%Guardar%%%
[im1,Referencia]=geotiffread('LC80280452015160LGN00_B2.TIF');
info=geotiffinfo('LC80280452015160LGN00_B2.TIF');
geotiffwrite('toar',toar,Referencia,'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
this is te equation wich I'm having trouble.
<</matlabcentral/answers/uploaded_files/54058/Sin%20t%C3%ADtulo.png>>
where PTOA, Ps, and Ta are images
Diego Díaz-Barrigahttps://ww2.mathworks.cn/matlabcentral/profile/authors/8272212-diego-diaz-barrigatag:ww2.mathworks.cn,2005:Question/4460992019-02-20T19:14:08Z2019-02-20T19:14:08ZNeed help to write a function to find the mahalonobis distance using 3 variables between two vectorsI am trying to write a function to find the mahalonobis distance between two vectors.
Below is my code, but for some reason its not working
function mhlbdist = Mahadist(A,B,M) % Vector A and B and covariance matrix M
mhlbdist = zeros(1,150);
m = inv(M);
for i=1:150
mhlbdist(1,i) = (A(i,;)-B)*m*(A(i,;)-B)';
end
end
S = [5.0000, 3.5000, 1.4600, 0.2540];
T = cov(S);
u = zeros(1,150);
for i=1:length(Tnew) %Tnew is the iris dataset
u(i,1) = Mahadist(S,Tnew(i,1:4),T);
end
plot(1:length(Tnew),u)Apurva Jariwalahttps://ww2.mathworks.cn/matlabcentral/profile/authors/12677662-apurva-jariwalatag:ww2.mathworks.cn,2005:Question/4460252019-02-20T13:10:35Z2019-02-20T19:14:08ZReal time plotting - Matlab GUIHey y'all. I'm running into a little problem. Can y'all please help?
I am reading values from an instrument and trying to plot these values continuously when the push button (converted it to a toggle button) is pressed. I am using Guide for my GUI.
please note that the code isn't complete yet, but I am testing the real time plotting at this point. I'm not sure how to get the while (when pressed) condition for the push_button. Also, I took the section of code within the loop to a seperate file and was able to plot it. However, Matlab plots one point at a time and I was not able to get it such that it connected the points.
Thanks.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Establish Device (Boonton 4500C RF Power Analyzer) Communication
ni=NET.addAssembly('NationalInstruments.VisaNS');
res=NationalInstruments.VisaNS.ResourceManager.GetLocalManager.FindResources('?*').cell;
dev=NationalInstruments.VisaNS.ResourceManager.GetLocalManager.Open(res{1});
% Change device units to Watts
dev.Write('CALC:UNIT W')
grab_avg_time = datetime();
grab_avg = [];
while get(pushbutton11, 'value')
grab_avg= strsplit((string(dev.Query('FETC1:ARR:CW:POW?'))),','); %Fetch data from PM and convert to string
pause(2)
grab_avg = str2num(c(2)) %Average Power - Convert String to Number and place in array
pause(0.5)
grab_avg_time = datetime('now');
pause(0.5)
plot(grab_avg_time,grab_avg, '--*')
hold on
end
% Update handles structure
guidata(hObject, handles);George Diamondhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14787350-george-diamondtag:ww2.mathworks.cn,2005:Question/4460982019-02-20T19:12:54Z2019-02-20T19:12:54ZApp Designer and ArduinoHi,
I am designing an interface in the App Designer. I have an Arduino board connected to some sensors. I would like to be able to run the interface multiple times, but right now I run it once perfectly and when I click run again it tells me I have an existing connection at my COM port and I need to clear it. I am unsure how to do this as I am very new to app designer! Any help would be greatly appreciated!
Thanks!Allison McCradyhttps://ww2.mathworks.cn/matlabcentral/profile/authors/11456093-allison-mccradytag:ww2.mathworks.cn,2005:Question/4460782019-02-20T17:00:41Z2019-02-20T19:10:52ZMatlab for research purposeCan we use published matlab models, found on file exchange, for our own research? If not, how do we use published models for research purpose?Rudraksh Haranhttps://ww2.mathworks.cn/matlabcentral/profile/authors/9614449-rudraksh-harantag:ww2.mathworks.cn,2005:Question/4460952019-02-20T18:21:12Z2019-02-20T19:09:16ZReturn matrix of maximum valuesI have a matrix of the form:
a =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
column 1 & 2 represent x,y positions while col 3-5 represent intensity. I obtained the maximum and index of the intensity for each position from [M,I] =max(a(:,3:5),[],1). I am struggling with how to obtain the x,y positions corresponding to each maximum intensity. Any help would be appreciated. Thanks.Folu Yusufhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12810130-folu-yusuftag:ww2.mathworks.cn,2005:Question/4447312019-02-13T11:33:56Z2019-02-20T19:07:45Zcalculating x when y is > 0Hello
I have plotted a changing distance (d(x)) with time using cftool and calculated the function. Its derivative was calculated and this is v(x). when plotted with fplot the initial Y values are 0. I am calculating the x position at which this rises above the x axes (y>0). To do this i made v(x) equivalent to 1 (==1) and evluated x yet:
>>v(x)==1
ans =
(4119*x^2)/10000 - (1787*x)/5000 + 891/2500 ==1
>> eval x
x =
x
Will someone please help to calculate this? i can measure the x value directly. It is preferable to standardise this procedure.
GS.Gavin Seddonhttps://ww2.mathworks.cn/matlabcentral/profile/authors/6295967-gavin-seddontag:ww2.mathworks.cn,2005:Question/4459702019-02-20T08:22:32Z2019-02-20T19:06:22ZError using horzcat with num2str function for creating character class>>I am not understanding why the for double figure value, it is creating problems. Could anyone please help me with the situation?
Nt=10;Bd=9;Ns=1;
Str=['psd_c_',num2str(Nt),'_by_',num2str(Bd)','_shaded_',num2str(Ns)]
Str =
psd_c_10_by_9_shaded_1
But,
Nt=10;Bd=10;Ns=1;
Str=['psd_c_',num2str(Nt),'_by_',num2str(Bd)','_shaded_',num2str(Ns)]
Error using horzcat
Dimensions of matrices being concatenated are not consistent.MD RAQUIBUZZAMANhttps://ww2.mathworks.cn/matlabcentral/profile/authors/9041699-md-raquibuzzamantag:ww2.mathworks.cn,2005:Question/4457512019-02-19T08:32:59Z2019-02-20T19:02:13ZHow to read matfile from guide Dear all,
I have a mat file that consist of timetable data of 705 x 3
I created a button using Guide
Now i want to load this data in matlab workspace as well as store teh data in a variable say S.
I gave the follwing code in call back
load sensorlog_20190126_101635.mat
but not getting the variable loaded
Chandra Bhushanhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14127046-chandra-bhushantag:ww2.mathworks.cn,2005:Question/2774692016-04-06T10:45:06Z2019-02-20T19:00:30ZConvert MATLAB code to PythonOkay I've got this project based on Image Processing and it includes functions like bsxfun, bwlabel, etc, the inner working of which I have no idea.
I need the MATLAB code to be converted to Python but due to time and knowledge constraints, I cannot convert it manually. Is there any program that does this conversion for me?
I use SDC Morphology Toolbox for MATLAB for the code.
Thanks!Nikhil Hegdehttps://ww2.mathworks.cn/matlabcentral/profile/authors/4366063-nikhil-hegdetag:ww2.mathworks.cn,2005:Question/993572009-06-27T01:11:00Z2019-02-20T18:59:09ZCan I create a pushbutton that displays more than one line of text in MATLAB?I would like to create a pushbutton that has more than one line displayed as its 'string'.
MathWorks Support Teamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:ww2.mathworks.cn,2005:Question/4460972019-02-20T18:57:13Z2019-02-20T18:57:13ZProblems accessing Bing speech service with webwriteI cannot seem to send audio data to Bing Speech service with the webwrite command. Sending a uint8 array obtained by reading in a wav file (i.e., including it as the data element in the webwrite statement) does not work . I have successfully used uint8 arrays in calls to the service with other scripting languages. Also, when I try setting the MediaType weboption to 'audio/PCMA', I get an error message "The media type 'audio/PCMA' is not permissible for numeric or logical data." What's that about? It seems to conflict with the documentation regarding data handling in webwrite.Patrick Shoemakerhttps://ww2.mathworks.cn/matlabcentral/profile/authors/8356030-patrick-shoemakertag:ww2.mathworks.cn,2005:Question/4458252019-02-19T14:44:12Z2019-02-20T18:55:15ZHow to modify this code to make it import values from a file?Hi,
The following code opens a file (named "Pulse.acc") and writes c, s and t values as follows:
0 1 0
0 2 0
0 3 0
It also opens another file (named :Case.tcl") and writes each case number.
Each case over-writes the previous one.
I am now trying to import the values of s from the attached file (named "result_40.txt"). This file contains 40 columns and 10 rows. Each value in the columns will be printed in "Pulse.acc" file and excute OpenSees software model (along with c and t values. For example: 0 1 0, as shown above). This needs to continue until the 10th value in the column. Then, the second column starts.
The values of c and t will continue to be zero, so they could be left as below.
It would be great if a folder can be opened for the outputs from each column and numbered sequentially.
I hope I could explain what I want clearly, and please feel freel to let me know if I need to explain it further.
c=[0 0 0];
s=[1 2 3];
t=[0 0 0];
for j = 1:3
fidP = fopen('Pulse.acc','w+');
fidC= fopen('Case.tcl','w+');
fprintf(fidP, '%d\n%d\n%d',c(j), s(j), t(j));
fprintf(fidC, 'set case %d',j);
fclose(fidP);
fclose(fidC);
!OpenSees Model.tcl
endIsmail Qeshtahttps://ww2.mathworks.cn/matlabcentral/profile/authors/10292327-ismail-qeshtatag:ww2.mathworks.cn,2005:Question/4460612019-02-20T15:50:42Z2019-02-20T18:51:33ZFind clusters with specific value in 3D matrixHello,
I have an image of the size (91*109*91). The image contains voxels with values from 0 to 1. Now I would like to discard all voxels instead of those meeting the following conditions:
They have a value smaller than .05
they are part of cluster (connected voxels) of minimum 30 voxels with value < .05
At the end, I would like to have a 91*109*91 matrix/image containing only clusters of voxels with a value < 0.05.
I can figure out the first condition, what’s tricky for me is the second condition.nivonshttps://ww2.mathworks.cn/matlabcentral/profile/authors/13202886-nivonstag:ww2.mathworks.cn,2005:Question/4454802019-02-17T23:55:27Z2019-02-20T18:50:53Zvectorize operation on image processingHi! I want to vectorize the variable final on this code :
for i = 1:sz1
for j = 1:sz2
if (bw(i,j)==1)
final(i,j,1)=255;
final(i,j,2)=0;
final(i,j,3)=0;
else
final(i,j,1)=I(i,j,1);
final(i,j,2)=I(i,j,2);
final(i,j,3)=I(i,j,3);
end
end
end
bw : black and white array
I : the original image
final : the array i want to store the values
I want to vectorize it because i want to speed up my code.
Can enyone help?
thnks
thanos patrikashttps://ww2.mathworks.cn/matlabcentral/profile/authors/9429040-thanos-patrikastag:ww2.mathworks.cn,2005:Question/4440832019-02-09T17:07:05Z2019-02-20T18:50:11Zismethod(string('test'), 'endsWith') under R2016b and 2018bR2016b:
ismethod(string('asd'), 'endsWith')
ans = logical(1)
R2018b:
ismethod(string('asd'), 'endsWith')
ans = logical(0)
Is this documented? I did not finf in in the release notes.
Actually ismethod uses the class of the first input. But for string there seems to be an exception. Is this the correct usage:
data = string('asd')
ismethod(class(data), 'endsWith')
?Janhttps://ww2.mathworks.cn/matlabcentral/profile/authors/869888-jantag:ww2.mathworks.cn,2005:Question/4456092019-02-18T16:20:45Z2019-02-20T18:47:45ZHow to calculate sum of all the possible combinations of two vector elementsI have two vectors A and B with different lengths. The B vector always have 4 elements. How can I obtain the vector C containing sum of all the possible combinations of elements of B vector with A.
For example B= [1 2 3 4] and A= [0.1 0.2 0.3 0.4 0.5 0.6]
Then C= [1.1 1.2 1.3 1.4 1.5 1.6 2.1 2.2 2.3 2.4 2.5 2.6 3.1 3.2 3.3 3.4 3.5 3.6 4.1 4.2 4.3 4.4 4.5 4.6]
Thank youDavoudhttps://ww2.mathworks.cn/matlabcentral/profile/authors/3867523-davoudtag:ww2.mathworks.cn,2005:Question/4456782019-02-18T22:21:24Z2019-02-20T18:41:00ZHow to solve diffusion equation in spherical coordinate using Matlab?PDE toolbox in Matlab expects the equations in Cartesian coordinate. In this page it says what the general shape of the equations should be: https://nl.mathworks.com/help/pde/pde-coefficients.html
that is:
I want to solve the diffusion equations:
Thus, in my case m, a, and f are zero. If we are in Cartesian coordinate then d is one and c, the diffusion constant, is for example 0.001. However, I want to solve the equations in spherical coordinates. Here is a link to Laplacian in spherical coordinate:
http://mathworld.wolfram.com/LaplacesEquationSphericalCoordinates.html
How can I solve the diffusion equation in the spherical coordinates in Matlab? or How can I determine the matrix of coefficienct "c" in spherical coordinates?Yasharhttps://ww2.mathworks.cn/matlabcentral/profile/authors/4477665-yashartag:ww2.mathworks.cn,2005:Question/3182342016-12-26T22:31:13Z2019-02-20T18:40:10ZConnecting Matlab with VR headset.Hi guys,
Is there anyway of connecting Matlab with VR headset? I mean specifically Samsung Gear VR (I would use mirroring from PC to Samsung Gear VR with compatible Samsung phone).
I have a 3D curve created using Matlab and I am trying to find a way how to connect it with VR headset, as well I need to be able to rotate with the curve.
Note: Don't worry, I have been using google, I just haven't found anything yet.Franta Cymorekhttps://ww2.mathworks.cn/matlabcentral/profile/authors/9262056-franta-cymorektag:ww2.mathworks.cn,2005:Question/4460822019-02-20T17:21:29Z2019-02-20T18:38:45Zmex -setup does not workI was trying to setup mex in 2018b on mac. However I got the following
>> mex -v -setup
Verbose mode is on.
... Looking for compiler 'Xcode with Clang' ...
... Looking for environment variable 'DEVELOPER_DIR' ...No.
... Executing command 'xcode-select -print-path' ...Not enough input arguments.
Does any one know how to deal with this?Mingxi Liuhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13652687-mingxi-liutag:ww2.mathworks.cn,2005:Question/222011-01-11T16:13:42Z2019-02-20T18:37:57ZHow do I display different boxplot groups on the same figure in MATLAB?I would like to generate boxplots on the same figure for two different groups, observed and simulated temperatures for January to December with the x-axis being months. The two different groups need to be represented in different colors. The spacing between the boxplots also need to be user-definable.Doug Hullhttps://ww2.mathworks.cn/matlabcentral/profile/authors/6503672-doug-hulltag:ww2.mathworks.cn,2005:Question/4460442019-02-20T14:34:09Z2019-02-20T18:37:48Zcombining (concat) matrix in loop to get desired output plotHi,
I have two plots gotten from (general_load and special_load), they are time vs force. I want to create a loop where I can concat/merge the special load multiple times into the general load where N is the first position on the general_load and i is the number of times (the distance between the special loads must be N) .
Here is where it gets tricky since I want to keep the plots intact the time must be adjusted according ( eg, when the 1st special_load is added at t=50sec to the general load the entire time column in the matrix must be added by 50 such that there is a seamless connection.
A=xlsread('general_load.xlsx');
B=xlsread('test_gust_special_load');
a_length = A(end,1);
b_length = B(end,1);
N = 10;
%% for one special load in the general i used this approach
C1 = A(A(:,1)<=N,:);
C2 =[B(:,1)+N,B(:,2)];
C3 =A(A(:,1)>N,:);
C4=[C3(:,1)+b_length,C3(:,2)];
CT = vertcat(C1,C2);
%% but I am unable to get the for loop
for i= C4(1,1)+N:N:a_length
P1 =C4(C4(:,1)<=i,:);
P2 =[B(:,1)+i,B(:,2)];
PT = vertcat(P1,P2);
c_length=PT(end,1);
C4=PT(PT(:,1)+c_length,PT(:,2));
end
Z = vertcat(CT,C4);
plot(Z(:,1),Z(:,2));liju Abrahamhttps://ww2.mathworks.cn/matlabcentral/profile/authors/9015747-liju-abrahamtag:ww2.mathworks.cn,2005:Question/4453212019-02-16T17:55:50Z2019-02-20T18:37:02ZHow to find shortest distance in 3D?Hello, Everyone!
I am trying to find the shortest path by using dijkstra's algorithm and I need to input 3-Dimensional nodes into the program.
Each 3-Dimensional nodes have x, y, z coordinates. I am trying to use Nx3 matrix to represent it or maybe Nx4 matrix include the node ID.
I found that there is a function which called graphshortestpath in matlab function.
I want to know that is it possible to input 3-Dimensional nodes and plot a graph to demonstrate the result?
If yes, please tell me how to do it or give me some examples. If the function cannot do it, please tell me how to do it by other methods.
Thank you very much!Antonio Smithhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14787536-antonio-smithtag:ww2.mathworks.cn,2005:Question/4386642019-01-07T19:12:11Z2019-02-20T18:25:32ZStrange behavior of the editor in the forumThe editor in the forum is still driving me crazy. With the old version I could at least type my messages in an external editor, but now the text field is too smart to allow this.
When I type some code (Ctrl-E to enter the code style, then "for i = 1:10"), the editor is such smart, that it adds an "end" automatically. But I do not want such an "end", because my example is clear already without it. After this line, I press Enter and Ctrl-E again to leave the code style. Now I have to spend some time to get rid of the "end".
Sometimes the text field seems to loose the focus partially. I've tested this in Firefox only: While the typed characters appear in the text field, Firefox interpretes the keystrokes also and scrolls through the page exhaustively, such that I cannot see, what I type anymore. I type some characters blindly and scroll back to check, if it is correct. With the next keystroke the page is scrolled again. This is extremely annoying.
When I leave the code style, there are a certain number of spaces infront of the cursor. Trying to delete them let me exceed the first character frequently, such that I delete the code style before. Therefore I need to use "Pos 1" at first, then "Shift+End" to mark all spaces, "Delete" to remove them and then I can start typing from the first character.
It is hard to insert a link, but even worse to insert a string without formatting. Because I appreciate the correct spelling of names of persons, I copy&paste the names from the display by copy&paste. Unfortunately the editor is such smart, that it inserts a link automatically and I need a bunch of keystrokes to make it a standard text. I should append a move of this, because during the editing some parts of the string disappear intermediately and reappear magically, when a space is added.
This feels very weird. I have not seen such a crazy and unintuitive editor before. Typing answers in the forum increases my stress level, because the interface does not treat keyboard inputs like any other software.
What a pity, that the field for typing is not recognized as text field anymore, such that the auto-spell-correction of the browser does not work. I apologize for all of my typos.
There are many forums with working editors for text, links, code and citations. Markdown, BBCode etc. are established methods. Matlab Answers has problems with the interface for many years now. It is time to fix and simplify this until it works, instead of making it smarter and cooler.
Has this topic been diskussed in (sorry, I'm typing blind again, because of the mentioned effects of scrolling away... darn) forum already? Do others suffer from the same problems? Is the editor more intuitive in other browsers than Firefox? Does somebody use an external editor like XEmacs + macros successfully to create answers with copy&paste including links and images?Janhttps://ww2.mathworks.cn/matlabcentral/profile/authors/869888-jantag:ww2.mathworks.cn,2005:Question/4460772019-02-20T16:57:15Z2019-02-20T18:25:28ZXCORR function to find the lag time between two signalsHello
I am using the XCORR function to find the lag time between two signals, but when processing the measured data the lag is always the same, physically it is not possible. I have noticed that the lags are whole numbers, is it possible to obtain correlation coefficients with lags with decimals?
Thank youPatrico Ortegahttps://ww2.mathworks.cn/matlabcentral/profile/authors/10539639-patrico-ortegatag:ww2.mathworks.cn,2005:Question/4460682019-02-20T16:19:40Z2019-02-20T18:25:19ZHow to measure the height of white pixels in column in a binary image?Hi Everyone,
I am very new to matlab imaging and matrix stuff.
----------------------------------------------------------------------------------
I have managed to create this image (1080x1920 logical) (as attached) from a colour video.
I want to be able to go along the x-axis, say 200 pixels and 800 pixels; and measure how many white pixels are on that column (y-axis).
Hopefully I can eventually convert these into real world values.
------------------------------------------------------------------------------------
Alternatively I would like to take the image and "mask" it then use regionprops to measure pixel area. Im not too sure what this term means or how to do it
Any advice or code anyone could give me would be very much appreciated as I have struggled on this task for weeks.
Many thanks
R MONTGOMERYhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14736061-r-montgomerytag:ww2.mathworks.cn,2005:Question/4405522019-01-20T00:25:37Z2019-02-20T18:20:00ZCombining 5 different bands to generate one sinlge image.How can I cobmine 5 different multispectral bands (R,G,B, NIR, RedEdge). They all are in .tiff version?Amit Bhasinhttps://ww2.mathworks.cn/matlabcentral/profile/authors/13741575-amit-bhasintag:ww2.mathworks.cn,2005:Question/4460932019-02-20T18:18:58Z2019-02-20T18:18:58ZIs there any way to create a ClassificationNaiveBayes model directly from a NaiveBayes model?I want to update some code that uses the deprecated NaiveBayes class, ideally without digging up the ancient training data in order to retrain a current model type, the key fields have obvious matches but there are many more fields with non-obvious meaning in the new class, is there any easy way to create a functional new model from the old one without the original training data?Anthonyhttps://ww2.mathworks.cn/matlabcentral/profile/authors/1359436-anthonytag:ww2.mathworks.cn,2005:Question/4459162019-02-19T23:27:58Z2019-02-20T18:17:36ZCan I use an array of Simulink Buses as the initial state of a memory block?I have a Simulink Bus (MyBus) that has a field (a_bunch_of_sub_buses) that is an array of type SubBus. If I try to use this in a Memory block, Simulink simply says that the Memory block has an invalid parameter x0 -- the initial condition. Can I not use a bus with an array of buses inside of it as the parameter of a Memory block, or am I doing something else wrong?Tucker McClurehttps://ww2.mathworks.cn/matlabcentral/profile/authors/781437-tucker-mccluretag:ww2.mathworks.cn,2005:Question/4460922019-02-20T18:16:44Z2019-02-20T18:16:44ZEquation of a plane %Input command; 1st vector
a=input('Enter the 1st pair of 3 vector elements in [square brackets]: ');
%Error message; 1st vector is not equal to 3 elements
if (numel(a)~=3)
disp('The vector’s elements must equal 3. Try again.');
else
%Input command; 2nd vector
b=input('Enter the 2nd pair of 3 vector elements in [square brackets]: ');
%Error message; 2nd vector is not equal to 3 elements
if (numel(b)~=3)
disp('The vector’s elements must equal 3. Try again.');
%Dot product calculation
else
c=dot(a,b);
k=num2str(c);
disp('The dot product of the vectors is: ');
disp(k)
end
end
%Angle between a and b
angle=acosd(c/(norm(a)*norm(b)));
e=num2str(angle);
disp('Degree angle between the vectors is:')
disp(angle)
f=deg2rad(angle);
disp('and in radians:')
g=num2str(f);
disp(g)
%Cross product calculation
h=cross(a,b);
i=num2str(h);
disp('The cross product of the vectors is: ')
disp(i)
%Equation of the plane
syms x y z
j=input('Enter the prependicular distance from the origin: ');
if j<=0
disp('The distance cannot be zero or negative. Try again.')
else
k=i(1)*x + i(2)*y + i(3)*z == j;
l=num2str(k);
disp('The equation of the plane is: ')
disp(l)
end
I am trying to display the equation of the plane spanned by vector a and b input by the user:
I want the values of the cross product vector to be displayed in cartesian form as: firstvalue*x + secondvalue*y + thirdvalue*z = d (input from the user)
Is there a command that will ensure that if one of the cross product values is zero, the variable(x, y or z) does not appear in the final output?
Can the result be displayed without the * and the signs of the variables are either + or -, so the output is more professional?
Any suggestions or hints would be welcome. Thank you. Mughees Asifhttps://ww2.mathworks.cn/matlabcentral/profile/authors/14529788-mughees-asiftag:ww2.mathworks.cn,2005:Question/4460912019-02-20T18:15:21Z2019-02-20T18:15:21ZHow to stop files from being saved with an extra .XML extension?I have recently started having a problem with files having a ".XML" extension added to it.
If i make a new function and then try to save it, it saves to my folder as "filename.m.XML". And then i have to manually remove the .XML from the name in order to execute the file.
It also comes up when i am trying to use the saveas built-in command. I enter the command: saveas(fig,'FigureName','tiff') or saveas(fig,'FigureName.tif') and, in both cases I get a file pop up in my folder that is "FigureName.tif.XML" and then I get an error.
In both cases, this extra .XML shows up. How do I get it not to do that?
Alysson Mondorohttps://ww2.mathworks.cn/matlabcentral/profile/authors/6488900-alysson-mondorotag:ww2.mathworks.cn,2005:Question/685102013-03-25T09:53:06Z2019-02-20T18:04:58ZRemove rows or cols whose elements are all NaNHow can I remove rows or cols whose elements are all NaN ?
Withouot any dirty iterations?
For example,
A = [1 1 1 1 1 1 1 1 1 1;
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN;
1 1 1 1 1 1 1 1 1 1;
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN;];
should turned into
A = [1 1 1 1 1 1 1 1 1 1;
1 1 1 1 1 1 1 1 1 1];
This is just an example. Actually I have a very big matrix.
So I want a solution of this question to work well with my big matrix.Jeonhttps://ww2.mathworks.cn/matlabcentral/profile/authors/3497007-jeontag:ww2.mathworks.cn,2005:Question/4458892019-02-19T19:30:24Z2019-02-20T18:04:15ZNon Contact Vital Sign Monitoring SystemHi, I am currently working on a project "Non Contact Vital signs Monitoring System". I am using a 24Ghz radar IF signal to extract the heart rate and respiration rate.
Algorithm is
1. Output signal from the radar is given to A/D converter and sampled at 100Hz
2. Then signal is amplified
3. Output of amplifier is given to bandpass filter, For cardiac monitoring filter was set between 0.5 Hz and 2.5 Hz. For respiratory monitoring, the
filter was set between 0.05 Hz and 0.5 Hz
4. After band-pass filtering, each signal was processed by a Fast Fourier Transform (FFT) using a Hanning window
5. The result from the FFT conducted for each signal from the respective microwave radar after band-pass filtering set at between 0.5 Hz and 2.5 Hz was
multiplied 2) the frequency of the peak signal between 0.5 Hz and 2.5 Hz was assumed to correspond to heart rate. The same analytical process was
conducted between 0.05 Hz and 0.5 Hz to calculate respiratory rate
I want to develop a simulink model for this Algorithm and I am new to signal processing. I got this algorithm from IEEE paper i don't know to how extent this will work.
I need help in building this algorithm. I need help mainly in design simulink block 4th and 5th step in algorithm. It would great if someone could provide me a simulink block file for this algorithm
Email id: nvakhil009@gmail.comAkhil Nv Nairhttps://ww2.mathworks.cn/matlabcentral/profile/authors/12854978-akhil-nv-nairtag:ww2.mathworks.cn,2005:Question/4460892019-02-20T17:58:23Z2019-02-20T18:03:44ZProduct of elements in an arrayI have an array as such (3 5 7 11), I want to find out the unique multiples of these elements i.e.
1) product of pairwise elements -- 15, 21, 33, 35, 55, 77
2) product of three elements -- 105, 385, 231
3) product of four elements -- 1055.
I am currently confused as to how to go about it in an efficient way so that when I extend it to larger number of elements in the array, I don't explode my memory and kill my computer. Any help would be greatly appreciated.
Thanks
Raghavasimhan Thirunarayananhttps://ww2.mathworks.cn/matlabcentral/profile/authors/3932033-raghavasimhan-thirunarayanantag:ww2.mathworks.cn,2005:Question/4460882019-02-20T17:54:43Z2019-02-20T17:55:54ZHow do I use WinOnTop for GUIs?I have a main GUI with an axes object on which I display an image. Occasionally, the users need to calibrate distances on the image (using imdistline). Since the calibration operation is not needed often, they have asked that the associated objects (text boxes, command buttons, etc) be on a separate "popup window". (i.e., They don't want the objects for calibration cluttering the main GUI).
I cannot use the modal WindowStyle for the calibration GUI, because it would not allow the user to interact with the image axis on the main GUI until the calibration GUI is closed.
I found WinOnTop in the MATLAB File Exchange, which keeps a figure window on top of other windows, while allowing user interaction with the other windows. However, I can't get it to work with a GUI. If I insert the command ( WInOnTop(handles.figName) ) in the calibration GUI's OpeningFcn, I get an error saying that I cannot apply WinOnTop until the figure is visible. I cannot insert it into the OutputFcn, because I need the calibration GUI to wait until the calibration procedures are done before returning the values back to the main GUI.
Am I overlooking something? Is there a better way to do this?
Thank you in advance for all of your help.CAMhttps://ww2.mathworks.cn/matlabcentral/profile/authors/60313-cam