https://ch.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2019-02-18T16:02:38Ztag:ch.mathworks.com,2005:Question/4455802019-02-18T14:01:09Z2019-02-18T16:02:06ZHow can i measure the distance of each pixel of a binary image from a specified co-ordinate?I'm trying to measure error in roundness. I have got a point i.e., the center point co-ordinates(Xc,Yc). Now from this point i have to measure the distance of each pixel of the circle geometry so as to get the mean radius. So can anyone help me?Prathveraj Shettyhttps://ch.mathworks.com/matlabcentral/profile/authors/14207414-prathveraj-shettytag:ch.mathworks.com,2005:Question/4456042019-02-18T16:00:16Z2019-02-18T16:01:26ZCluster profile for deployed appsI have a deployed app running on machines where MATLAB is not installed. Hence, how do I create a "Cluster Profile" programmatically? Are there other ways to do this? Thanks.Adam Gogaczhttps://ch.mathworks.com/matlabcentral/profile/authors/3558327-adam-gogacztag:ch.mathworks.com,2005:Question/4456032019-02-18T16:00:13Z2019-02-18T16:01:08ZProblem viewing header imageHello!
I am generating a report using a Word Template. The template works without problems when using it directly from MS Word. When I insert it in my code though, the image header shows up as a red cross with the text "image can´t be displayed". I have tried to make the header image an inline image, so that it is on the same level as the text, but that didn´t change anything.
Here is part of the code:
import mlreportgen.dom.*;
doc = Document('Protokoll_1', 'docx', 'Template_Protokoll_1');
holeId = moveToNextHole(doc);
fprintf('Current hole ID: %s\n', holeId);
append(doc, Table_Init_1);
holeId = moveToNextHole(doc);
fprintf('Current hole ID: %s\n', holeId);
append(doc,Image('C:\Users\Konstantina\Documents\MATLAB/Bild1.png'));
close(doc);
rptview('Protokoll_1', 'docx');
Thanks in advance for your help!
KonstantinaDanielhttps://ch.mathworks.com/matlabcentral/profile/authors/3178863-danieltag:ch.mathworks.com,2005:Question/4455192019-02-18T07:37:13Z2019-02-18T16:02:38ZMigration between MatLab Version: Usage of linprog and fminconHi there!
My collegue (Petros) and myself are working on a Project to replace and old Solution using MatLab R2010b with a new Solution using MatLab R2018a.
Having said that, we face some issue as there are some changes between the two MatLab versions in the functions fmincon and linprog that we are using.
Initially, we had quite large differences. This was mainly due to differences in fmincon itslef. We called fmincon with the following options:
We then compare the two fmincon.m files in R2010b and R2018a and figured out, that there have been significant changes - specially around the options. By adding all Options for which the default has changed, and that we did not include in our call to the R2010b values, we got much closer:
Please not: The true default for Algorithm in R2010b is trust-region-reflective, but by inspecting fmincon.m, in line 490, when is not empty, fmincon.m changes the algorithm to active-set.
With that, we are now much closer to the Results in R2010b. But not yet there.
Are there any other options that we need to change in order ot get the same results with fmincon between the two versions?
Having said that, we are also useing a function called linprog in our tool. This one also changes in the options. We are calling it three times with different options:
Resulting in the following call in linprog.m line 265 in R2010b (if I'm not mistaken):
Resulting in the following call in linprog.m line 297 in R2010b (if I'm not mistaken):
Resulting in the following call in linprog.m line 256 in R2010b (if I'm not mistaken):
In R2018a, I see, that the Simplex option is no longer available.
However, we have a number of new options:
Algorithm with default dual-simplex
MaxTime with default Inf
Preprocess with default basic
TolCon with default []
In the old linprog.m file, I find different algorithm being used internally around line 221:
In R2018a, I find:
I do not find simplex anymore nore active-set. Also for interior-point, I have two version. I do also not find anything useing simplex or qpsub in the R2018a linprog.m file. How do we need to call linprog in R2018a to get same results like in R2010b?
Also, could you help us with an a bit more detailed description on what the different algorithms in the two functions (fmincon and linprog) in R2018a are supposed to do?
Thanks a lot
StefanPetros Almpanopouloshttps://ch.mathworks.com/matlabcentral/profile/authors/8462763-petros-almpanopoulostag:ch.mathworks.com,2005:Question/4455872019-02-18T14:44:21Z2019-02-18T15:59:42ZHow display the same image in two figuresThe problem is when I execute one of the figures alone it display the image that I selected but when I execute the figures in this order , first main.fig then TestingPhase.fig . the TestingPhase.fig does not display the selected image in img_axes after that the showimage.fig also it does not display the same image, why ?asma khaledhttps://ch.mathworks.com/matlabcentral/profile/authors/12364514-asma-khaledtag:ch.mathworks.com,2005:Question/4455312019-02-18T09:08:02Z2019-02-18T15:59:38Zhelp with ode solvers non-linear ode 1st law of thermodynamicsHello all:
I am trying to solve the ODE's:
d2y/dt2=-g+(P-Pa)*Ap
dP/dt=k*P*((1/m) *(dm/dt) - (k/(L+y))*(dy/dt))
dm/dt=(m/V) [q-c*Ao*(Pa/P)^(1/k) * {2*k/(k-1) * P*V/m *(1-(Pa/P)^((k-1)/k))}^0.5
V(y)=Ap*(L+y)
where w,Ao,q,Ap,Pa,k,L,g are all constants. but P(t),m(t), y(t) are functions of t
I wrote the following M-file but it looks like it's not working for the m variable. Is there anyting wrong with code or state space variable?
##############################################
clear;close all
global Pa;global A;global Wp;global q;global Ao,global c;global L;global k;
Pa=101000;
d=.05;
Wp=7;
q=2;
Ao=0.01;
c=.1;
L=0.75;
k=1.4;
Te=300;
A=0.25*pi*d^2;
mass=(Pa*L*A)/(287*Te);
tic
W=200;
tf=10;
Fs = .1; %sampling rate
Ts = 1/Fs; %sampling time interval
tspan =0:Fs:tf; %sampling period
y0=[0,.0,101000,mass];
[t,y]=ode45(@Sample01,tspan,y0,[]);
%y[YfreqDomain_d,frequencyRange_d]=positiveFFT(y(:,1),Fs);
subplot(2,2,1);plot(t,y(:,1),'k');
subplot(2,2,2);plot(t,y(:,2),'k');
subplot(2,2,3);plot(t,y(:,3)/Pa,'k');
subplot(2,2,4);plot(t,y(:,4),'k');
dlmwrite('tssst',[y]);
toc
HERE IS THE FUNCTION OF STATE SPACE
function y_dot=Sample01(t,y)
global Pa;global A;global Wp;global q;global Ao,global c;global L;global k;
y_dot=zeros(4,1);
y_dot(1)=y(2);
y_dot(2)=-Wp*9.81/Wp+(y(3)-Pa)*A/Wp;
y_dot(3)=y(3)*((k/y(4))*y_dot(4)-(k/(L+y(1)))*y(2));
y_dot(4)=y(4)/(L+y(1))*(q-c*Ao*(Pa/y(3))^(1/k)*((2*k/(k-1))*y(3)*(L+y(1))/y(4)*(1-(Pa/y(3))^((k-1)/k)))^0.5);
Ahmed Sowayanhttps://ch.mathworks.com/matlabcentral/profile/authors/8027473-ahmed-sowayantag:ch.mathworks.com,2005:Question/4455982019-02-18T15:47:36Z2019-02-18T15:59:11ZHow to import values from a column in "for" loop?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://ch.mathworks.com/matlabcentral/profile/authors/10292327-ismail-qeshtatag:ch.mathworks.com,2005:Question/4456022019-02-18T15:58:09Z2019-02-18T15:58:09ZMatlab Runtime not linking properlyI am trying to run a compiled Matlab code with another computer (both Linux). Usually this works out fine; however, now I ran into a strange problem:
The code compiles and allows installatiton without errors; however, when I try to start it (its name is ShowerGUI) with
mikael@mycomputer ~/Documents $ /usr/local/MATLAB/COMPILED/ShowerGUI/application/run_ShowerGUI.sh /usr/local/MATLAB/Matlab_Runtime/v95
, a following error message appears:
------------------------------------------
Setting up environment variables
---
LD_LIBRARY_PATH is .:/usr/local/MATLAB/Matlab_Runtime/v95/runtime/glnxa64:/usr/local/MATLAB/Matlab_Runtime/v95/bin/glnxa64:/usr/local/MATLAB/Matlab_Runtime/v95/sys/os/glnxa64:/usr/local/MATLAB/Matlab_Runtime/v95/sys/opengl/lib/glnxa64
/usr/local/MATLAB/COMPILED/ShowerGUI/application/ShowerGUI: error while loading shared libraries: libmwlaunchermain.so: cannot open shared object file: No such file or directory
I am sure that the linking folder has been set up correctly - I am using exactly the same command (apart from the program name) for another program which works well.
Mikael Agopovhttps://ch.mathworks.com/matlabcentral/profile/authors/13066523-mikael-agopovtag:ch.mathworks.com,2005:Question/4456012019-02-18T15:53:19Z2019-02-18T15:56:30ZCan anyone point out the mistake in this program? It's regarding writing a function to check if the entered date is valid or not.I am given with this problem.
Write a function called valid_date that takes three positive integer scalar inputs year, month, day. If these three represent a valid date, return a logical true, otherwise false. The name of the output argument is valid. If any of the inputs is not a positive integer scalar, return false as well. Note that every year that is exactly divisible by 4 is a leap year, except for years that are exactly divisible by 100. However, years that are exactly divisible by 400 are also leap years. Note that your solution must not contain any of the date related built-in MATLAB functions.
Here is the code that I have written, but it gives wrong answers for date such as 31st April 2018 (2018,4,31). Ideally the program should give me logical 0, however, it gives me logic 1.
function [valid]=valid_date(year, month, day)
if isscalar(year) && year>0 && year~=0 && isscalar(month) && month>0 && month~=0 && isscalar(day) && day>0 && day~=0 && month<=12
%leap year
if mod(year,4) == 0 && mod(year, 100)~= 0 || mod(year,400)==0 && month==2 && days<=29
%for february
valid=true;
else
valid=false;
end
%for rest of the months
if month==4 || month==6 || month==9 || month==11 && day<=30
valid=true;
elseif month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month== 12 && day<=31
valid=true;
else
valid=false;
end
%not a leap year
if month==2 && day>28
valid=false;
end
%rest of the months
if month==4 || month==6 || month==9 || month==11 && day<=30
valid=true;
elseif month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month== 12 && day<=31
valid=true;
else
valid=false;
end
else
valid=false;
end Sanjeeb Bharalihttps://ch.mathworks.com/matlabcentral/profile/authors/14790037-sanjeeb-bharalitag:ch.mathworks.com,2005:Question/4455462019-02-18T10:54:47Z2019-02-18T15:56:10ZHow can I equate all values of one vector to another and get the value ? Please find the example belowIf I have
dataA = [1,2,3,4,5,6,7,8,9];
dataB = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1];
I need to equate for example: 1 = 0.1, 2=0.2, 3=0.3 so that if I ask value(7) it should display 0.7
Thank you in Advance.Rakesh Yadav Kodarihttps://ch.mathworks.com/matlabcentral/profile/authors/10084164-rakesh-yadav-kodaritag:ch.mathworks.com,2005:Question/4452082019-02-15T18:49:17Z2019-02-18T15:52:13ZError massage "failed to generate binary outputs"I have made a model for a flasher in Simulink, but when I pressed the button ''deploy to hardware'' to generate the code for the arduino Uno, I constantly get the error massage: "failed to generate all binary outputs''. I have already tried to restard the arduino, redownloading the arduino support package for simulink and changing the location of the simulation cache and code generation folder to another folder in "documents". I also haven't used any spaces in the file name.
You can find the full diagnostics here:
### Generating code into build folder: D:\persoonlijke map Davide\Documenten\MATLAB\Practicum_1_ert_rtw
### Invoking Target Language Compiler on Practicum_1.rtw
### Using System Target File: C:\Program Files\MATLAB\R2018a\rtw\c\ert\ert.tlc
### Loading TLC function libraries
### Initial pass through model to cache user defined code
.
### Caching model source code
### Writing header file Practicum_1_types.h
### Writing header file Practicum_1.h
### Writing source file Practicum_1.c
### Writing header file rtwtypes.h
### Writing header file multiword_types.h
### Writing header file Practicum_1_private.h
### Writing header file rtmodel.h
.
### Writing source file Practicum_1_data.c
### Writing source file ert_main.c
### TLC code generation complete.
### Evaluating PostCodeGenCommand specified in the model
### Using toolchain: Arduino AVR v1.8.1 | gmake (64-bit Windows)
### 'D:\persoonlijke map Davide\Documenten\MATLAB\Practicum_1_ert_rtw\Practicum_1.mk' is up to date
### Building 'Practicum_1': "C:\PROGRA~1\MATLAB\R2018a\bin\win64\gmake" -f Practicum_1.mk all
D:\persoonlijke map Davide\Documenten\MATLAB\Practicum_1_ert_rtw>cd .
D:\persoonlijke map Davide\Documenten\MATLAB\Practicum_1_ert_rtw>if "" == "" ("C:\PROGRA~1\MATLAB\R2018a\bin\win64\gmake" -f Practicum_1.mk all ) else ("C:\PROGRA~1\MATLAB\R2018a\bin\win64\gmake" -f Practicum_1.mk )
C:/ProgramData/MATLAB/SupportPackages/R2018a/3P.instrset/arduinoide.instrset/arduino-1.8.1/hardware/tools/avr/bin/avr-g++ -std=gnu++11 -fpermissive -fno-exceptions -fno-threadsafe-statics -c -g -w -ffunction-sections -fdata-sections -MMD -DARDUINO=10801 -MMD -MP -MF"MW_digitalio.dep" -MT"MW_digitalio.o" -Os -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -D_RUNONTARGETHARDWARE_BUILD_ -DMODEL=Practicum_1 -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DTID01EQ=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DEXIT_FAILURE=1 -DEXTMODE_DISABLEPRINTF -DEXTMODE_DISABLETESTING -DEXTMODE_DISABLE_ARGS_PROCESSING=1 -DSTACK_SIZE=64 -D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ -DRT -DMW_TIMERID=1 -DMW_PRESCALAR=256 -DMW_TIMERCOUNT=59286 -DMW_SCHEDULERCOUNTER=1 -D_RTT_BAUDRATE_SERIAL0_=9600 -D_RTT_ANALOG_REF_=0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -DEXIT_FAILURE=1 -DEXTMODE_DISABLEPRINTF -DEXTMODE_DISABLETESTING -DEXTMODE_DISABLE_ARGS_PROCESSING=1 -DSTACK_SIZE=64 -DRT -DMODEL=Practicum_1 -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -ID:/persoonlijke map Davide/Documenten/MATLAB -IC:/ProgramData/MATLAB/SupportPackages/R2018a/toolbox/target/supportpackages/arduinobase/include -ID:/persoonlijke map Davide/Documenten/MATLAB/Practicum_1_ert_rtw -ID:/persoonlijke map Davide/Documenten/Practica -IC:/PROGRA~1/MATLAB/R2018a/extern/include -IC:/PROGRA~1/MATLAB/R2018a/simulink/include -IC:/PROGRA~1/MATLAB/R2018a/rtw/c/src -IC:/PROGRA~1/MATLAB/R2018a/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2018a/rtw/c/ert -IC:/ProgramData/MATLAB/SupportPackages/R2018a/3P.instrset/arduinoide.instrset/arduino-1.8.1/hardware/arduino/avr/cores/arduino -IC:/ProgramData/MATLAB/SupportPackages/R2018a/3P.instrset/arduinoide.instrset/arduino-1.8.1/hardware/arduino/avr/variants/standard -IC:/ProgramData/MATLAB/SupportPackages/R2018a/3P.instrset/arduinoide.instrset/arduino-1.8.1/libraries/Servo/src -IC:/ProgramData/MATLAB/SupportPackages/R2018a/toolbox/target/supportpackages/arduinotarget/include -IC:/ProgramData/MATLAB/SupportPackages/R2018a/toolbox/target/supportpackages/arduinotarget/scheduler/include -IC:/ProgramData/MATLAB/SupportPackages/R2018a/3P.instrset/arduinoide.instrset/arduino-1.8.1/hardware/tools/avr/avr/include/avr -IC:/ProgramData/MATLAB/SupportPackages/R2018a/toolbox/target/shared/externalmode_daemon/include -o MW_digitalio.o C:/ProgramData/MATLAB/SupportPackages/R2018a/toolbox/target/supportpackages/arduinobase/src/MW_digitalio.cpp
avr-g++: error: map: No such file or directory
avr-g++: error: Davide/Documenten/MATLAB: No such file or directory
avr-g++: error: map: No such file or directory
avr-g++: error: Davide/Documenten/MATLAB/Practicum_1_ert_rtw: No such file or directory
avr-g++: error: map: No such file or directory
avr-g++: error: Davide/Documenten/Practica: No such file or directory
gmake: *** [MW_digitalio.o] Error 1
D:\persoonlijke map Davide\Documenten\MATLAB\Practicum_1_ert_rtw>echo The make command returned an error of 2
The make command returned an error of 2
D:\persoonlijke map Davide\Documenten\MATLAB\Practicum_1_ert_rtw>An_error_occurred_during_the_call_to_make
'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
operable program or batch file.
### Creating HTML report file Practicum_1_codegen_rpt.html
(36): warning: generic lexer warning: Unterminated 'C++' style comment
### Build procedure for model: 'Practicum_1' aborted due to an error.
Error(s) encountered while building "Practicum_1":
### Failed to generate all binary outputs.Davide Carishttps://ch.mathworks.com/matlabcentral/profile/authors/14652112-davide-caristag:ch.mathworks.com,2005:Question/4450222019-02-14T18:10:28Z2019-02-18T15:51:17ZQuestions about Multi Objective Linear Programming (MOLP) with 'fminimax'Hello, I have questions about 'fminimax' for Multi Objective Linear Programming (MOLP).
The settings for my optimization are on the below
I have concerns that if I change the values on the myfun (e.g., 7104057.18 , 1334616299.17) in terms of changing decimal, the 'X_All' value changes relatively severe (e.g., the patterns are changed between no decimal point and second decimal point). Is it common phenomena? and how do I understand and interpret it?
Second, I want to check whether the optimal values of X_ALL and fval_ALL from different setting that mentioned above are stable point. The MATLAB tells that these points are local minimum. But is it possible that the global minimum point can be returned in 'fminimax' ?
Thanks
x0 = ones(243,1);
P = [];
P = P.';
LB = zeros(243,1);
UB = ones(243,1);
TP = [];
aeq=[];
beq=[];
nonlcon = [@nonlinearcon];
%% options
opts_reduced = optimoptions(@fminimax,'MaxFunctionEvaluations', 10000000000);
%% fminimax
[x_ALL,fval_ALL] = fminimax(@myfun_MOLP,x0,P,TP,aeq,beq,LB,UB,nonlcon,opts_reduced);
%% myfun_MOLP
C = [123935;85425;....];
E = [12300389;....];
C = C.';
E = E.';
f(1)= 0 *((7104057.18- C*x ) /7104057.18) ; %% 100 is the arbitary weight number %%
f(2)= 100 *((1334616299.17- E*x ) /1334616299.17) ;
%%nonlinearcon
function [n,neq] = nonlinearcon(x)
neq = [5931530;29746801;....];
neq = neq.';
neq = neq*x - 531027688.5;
n = [];
endYoung Gwan Leehttps://ch.mathworks.com/matlabcentral/profile/authors/13645296-young-gwan-leetag:ch.mathworks.com,2005:Question/4455842019-02-18T14:23:14Z2019-02-18T15:50:38ZWhat is the solution for below code? It shows error t=0:0.001:2; %sec @ 1 khz sample rate
x=chirp(t,0,1,150); %start @ DC ,cross 150 HZ at t=1 sec
F=0:.1:100;
[y,f,t,p] = spectrogram (x,256,250,F,1E3,'yaxis');
% this is the same as calling spectrogram with no outputs
surf(t,f,10*log10(abs(p)),'edgeColor','none');
axis xy; axis tight; colormap(jet);view(0,90);
xlabel ('time');
ylabel('Frequench (HZ)');
[y,fs] =audioread('filename.wav');
NW=round(fs*0.025);
[,F,T,P]= spectrogram(y,NW,[],[],fs);
Error using Spectrogram>chkinput (
line252)
Xmust be a vector(either row or column)
Error in spectrogram (line166) chkinput (x);
Yasir Alihttps://ch.mathworks.com/matlabcentral/profile/authors/14557848-yasir-alitag:ch.mathworks.com,2005:Question/4456002019-02-18T15:48:44Z2019-02-18T15:48:44ZWarning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. I have coding such as this:
En = length(n); % n = number of data tottaly
Ex1= sum(x1); % Ex1= number of Depth
Ex2= sum(x2); % Ex2= number of Amax
Ex3= sum(x3); % Ex3= number of Mw
Ex4= sum(x4); % Ex4= number of Vs
Ex5= sum(x5); % Ex5= number of Distance
x1x2= dot(x1,x2);
x1x3= dot(x1,x3);
x1x4= dot(x1,x4);
x1x5= dot(x1,x5);
Ex1x2=sum(x1x2);
Ex1x3=sum(x1x3);
Ex1x4=sum(x1x4);
Ex1x5=sum(x1x5);
x1_2 = x1.^2;
x2_2 = x2.^2;
x3_2 = x3.^2;
x4_2 = x4.^2;
x5_2 = x5.^2;
Ex1_2 = sum(x1_2);
Ex2_2 = sum(x2_2);
Ex3_2 = sum(x3_2);
Ex4_2 = sum(x4_2);
Ex5_2 = sum(x5_2);
Ey1=sum(y1);
x1_y1=dot(x1,y1);
x2_y1=dot(x2,y1);
x3_y1=dot(x3,y1);
x4_y1=dot(x4,y1);
x5_y1=dot(x5,y1);
Ex1_y1=sum(x1_y1); %Ex1_y = number x1 multiplyied y
Ex2_y1=sum(x2_y1); %Ex2_y = number of x2 multiplied by y
Ex3_y1=sum(x3_y1);
Ex4_y1=sum(x4_y1);
Ex5_y1=sum(x5_y1);
A = [En Ex1 Ex2 Ex3 Ex4 Ex5;Ex1 Ex1_2 Ex1x2 Ex1x3 Ex1x4 Ex1x5;Ex2 Ex2_2 Ex1x2 Ex1x3 Ex1x4 Ex1x5;...
Ex3 Ex3_2 Ex1x2 Ex1x3 Ex1x4 Ex1x5;Ex4 Ex4_2 Ex1x2 Ex1x3 Ex1x4 Ex1x5;Ex5 Ex5_2 Ex1x2 Ex1x3 Ex1x4 Ex1x5];
At = A';
G = [Ey1;Ex1_y1;Ex2_y1;Ex3_y1;Ex4_y1;Ex5_y1];
Ai = inv(At);
I want to make an inversion task but, I got the massage like this "Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN"
Is there any one can help me to slove my probelm?
ThxAkhmad Muktafhttps://ch.mathworks.com/matlabcentral/profile/authors/7503568-akhmad-muktaftag:ch.mathworks.com,2005:Question/4455992019-02-18T15:48:43Z2019-02-18T15:48:43ZValidation Accuracy on Neural networkHello..I wonder if any of you who have used deep learning on matlab can help me to troubleshoot my problem. I don't understand why I got a sudden drop of my validation accuracy at the end of the graph? It's a simple network with one convolution layer to classify cases with low or high risk of having breast cancer. After the final iteration it displays a validation accuracy of above 80% but then suddenly it dropped to 73% without an iteration. I don't understand that.
Here's my code
%set training dataset folder
digitDatasetPath = fullfile('C:\Users\UOS\Documents\Desiree Data\Run
2\dataBreast\training2');
%training set
imdsTrain = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
%set validation dataset folder
validationPath = fullfile('C:\Users\UOS\Documents\Desiree Data\Run
2\dataBreast\validation2');
%testing set
imdsValidation = imageDatastore(validationPath, ...
'IncludeSubfolders',true,'LabelSource','foldernames');
%create a clipped ReLu layer
layer = clippedReluLayer(10,'Name','clip1');
% define network architecture
layers = [
imageInputLayer([256 256 1]);
% conv_1
convolution2dLayer(3,32,'Stride',1)
batchNormalizationLayer
clippedReluLayer(10);
maxPooling2dLayer(2,'Stride',2)
%fc
fullyConnectedLayer(100)
dropoutLayer(0.7,'Name','drop1');
%fc
fullyConnectedLayer(25)
dropoutLayer(0.8,'Name','drop2');
% fc layer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
% specify training option
options = trainingOptions('adam', ...
'InitialLearnRate',0.001, ...
'MaxEpochs',15, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',30, ...
'Verbose',false, ...
'Plots','training-progress');
% train network using training data
net = trainNetwork(imdsTrain,layers,options);
% classify validation images and compute accuracy
YPred = classify(net,imdsValidation);
YValidation = imdsValidation.Labels;
%calculate accuracy
accuracy = sum(YPred == YValidation)/numel(YValidation);
Andrik Rampunhttps://ch.mathworks.com/matlabcentral/profile/authors/14596665-andrik-rampuntag:ch.mathworks.com,2005:Question/4450262019-02-14T18:31:23Z2019-02-18T15:48:26ZHow can I generate an array of binary data of this form?The N is input.
I want to write a code which gives array of dimension (combin X N) where combin is all possible combination such that sum of each row is N/2.
Confusion? Let me explain with an example...
Let N = 4, I want output array of the following form
[0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0]
note that the sum of each row if N/2 = 2. Let's see another example...
if N=6, output should be
[0 0 0 1 1 1
0 0 1 0 1 1
0 0 1 1 0 1
0 0 1 1 1 0
0 1 0 0 1 1
0 1 0 1 0 1
..... so on...]
I have a code but it is very inefficient (and also it does not work for N>18 (also it's very slow)
A = dec2bin( 1:2^N-1)-'0';
required_array = A(sum(A,2)==N/2,:);Luqman Saleemhttps://ch.mathworks.com/matlabcentral/profile/authors/9731121-luqman-saleemtag:ch.mathworks.com,2005:Question/4455912019-02-18T15:09:17Z2019-02-18T15:48:26ZHow to store the coordinates of polygon found from for loop.?I am getting the coordinates of box polygon in the for loop and i want to store it in an array and also i want to draw these coordinates on single image. I am getting error because boxpolygon itself is itself a array.Ravi Singhhttps://ch.mathworks.com/matlabcentral/profile/authors/14454930-ravi-singhtag:ch.mathworks.com,2005:Question/1128032014-01-18T03:43:27Z2019-02-18T15:48:20ZHow to draw circle with imellipse?Hi
I want to draw a circle with imellipse. I used something like:
AA = imellipse(gca,[xmin ymin radius radius]);
but I can only specify the xmin and ymin of the circle, while I want to specify the center.
How can I do so?
Thanks!
Steven
Stevenhttps://ch.mathworks.com/matlabcentral/profile/authors/4880430-steventag:ch.mathworks.com,2005:Question/2145552015-05-01T05:56:12Z2019-02-18T16:02:30ZHow to convert Speech to TextI am doing project on speech signal analysis.how to convert speech to text any one help me nemala srinivasa raohttps://ch.mathworks.com/matlabcentral/profile/authors/5961873-nemala-srinivasa-raotag:ch.mathworks.com,2005:Question/4455972019-02-18T15:43:11Z2019-02-18T15:43:11ZAllocating pinned memory in matlab mex with CUDAI have an application where I call my own CUDA fucntions from a mex. However, the memory transferred can be very big (both input and output) and that means that pinned memory can help me speed up the process quite a lot.
I have seen several posts in teh internet and in hre mentioning that you can not use pinned memory (cudaMallocHost) with MTALAB variables, however all these are from 2017 or older. Now that we are in 2019, and the parallel computing toolbox, CUDA and MATLAB have changed a lot, is this still true? Can pinned memory not be used still? For applications where memory is critical this is a big drawback.Ander Bigurihttps://ch.mathworks.com/matlabcentral/profile/authors/11848854-ander-biguritag:ch.mathworks.com,2005:Question/4455822019-02-18T14:10:22Z2019-02-18T15:42:50ZHelp with Matlab code-pleaseGood afternoon,
I am trying to run the following code in MATLAB but get an error.
Error using *
Inner matrix dimensions must agree.
Error in vcqr (line 27)
e = y - x*bhat; % Generate residuals
Any help to fix the problem please?
Thanks
Oz
clear
load fish1
Z = [ones(111,1) stormy mixed];
X = [ones(111,1) d];
pihat = inv(Z'*Z)*(Z'*d);
tau = ['15';'25';'35';'45';'50';'55';'65';'75';'85'];
for i = 1:size(tau,1),
disp(i);
hamster = str2num(strcat('.',tau(i,:)));
boo = rq([ones(size(y)) Z*pihat],y,hamster);
[b,vc] = vcqr(boo,y,[ones(size(y)) Z*pihat],hamster);
[b,f,c,seq,conv] = mcmc_flat_fish1_mon2('iqrobj_fish',boo,vc,50000,y,[ones(size(y)),d],Z,hamster);
save(strcat('fish',tau(i,:),'_storm_v3_mon2'),'b','f','c','seq','conv');
[b,f,c,seq,conv] = mcmc_flat_fish2('iqrobj_fish',boo,vc,50000,y,[ones(size(y)),d],Z,hamster);
save(strcat('fish',tau(i,:),'_storm_v3_2'),'b','f','c','seq','conv');
end
% Here is the portion of the function related to the error:
vc = zeros(k,k);
b = zeros(k,2);
S = (1/n)*x'*x;
e = y - x*bhat; % Line 27Ozmandohttps://ch.mathworks.com/matlabcentral/profile/authors/2950000-ozmandotag:ch.mathworks.com,2005:Question/4455542019-02-18T11:39:40Z2019-02-18T15:41:05ZWhat is the equivalent of the function 'wait' after using 'imellipse' for the new function 'drawcircle' (version R2018b)?I am trying to use the new function 'drawcircle' to select a ROI and perform some analysis on a set of images.
Before, with the function 'imellipse', it was possible to interactively place an ellipse by clicking and dragging, then use wait to block the MATLAB® command line and finally double-click on the ellipse to resume execution of the MATLAB command line. See code below.
imshow('coins.png')
h = imellipse;
position = wait(h)
The function 'imellipse' still works but I would like to use the new function 'drawcircle' and do exactly the same. I can't seem to be able to find the solution to block and resume the execution of the command line. Therefore, my code is running to the end without taking into account the position of the modified ROI. DJRhttps://ch.mathworks.com/matlabcentral/profile/authors/4801517-djrtag:ch.mathworks.com,2005:Question/4455962019-02-18T15:31:07Z2019-02-18T15:31:40ZInvalid memory layout connection settingHello,
i receive the error "Invalid memory layout connection settingInvalid memory layout connection setting found in 'modelpath/dtc' output port 1. Please contact MathWorks for assistance with this error message" when Ctrl+D my model. The model contains a variant subsystem and the error is shown only in one variant.
I didn't find anything online to fix this error by myself. Could you please provide me some more information?
Unfortunately, I can't post the model due to confidentiality and i couldn't rebuild the error in a testmodel.
Thanks
MichaelMichael Kahlehttps://ch.mathworks.com/matlabcentral/profile/authors/9197420-michael-kahletag:ch.mathworks.com,2005:Question/4431312019-02-04T18:52:05Z2019-02-18T15:26:45ZUsing Interp1 when data has duplicatesHi,
I am working with Timeseries data. Time vs Population in a building. I have data from two different sources for the space population. The plot is shown in the image attached. I need to interpolate these two plot lines to identify Y(population) values from both sources at regular intervals of X(Time) values (i.e. Population at 1-min increment in time). I tried interp1 but both my data sources have duplicates (as my population changed multiple times within a min). The time steps for both data sources dont match in the original data. I need to keep the duplicates as they are required data points. I am not sure how to work around this issue to obtain Y values from both sources at the same time-steps.
PS: I used clear 'x' and 'y' values and then reobtain x and y values but it only gives me the same data points that I used to plot.
Thanks for the help.
Krishna Chaitanya Simmahttps://ch.mathworks.com/matlabcentral/profile/authors/6658734-krishna-chaitanya-simmatag:ch.mathworks.com,2005:Question/4455952019-02-18T15:25:33Z2019-02-18T15:25:33Zis there a way to access simulink online?Hi! I would like to know if there was a way to access Simulink online, like MATLAB online feature. Thanks :)Dhwani Vakilhttps://ch.mathworks.com/matlabcentral/profile/authors/8863968-dhwani-vakiltag:ch.mathworks.com,2005:Question/4449832019-02-14T15:44:28Z2019-02-18T15:25:20ZHow to loop multiple images in a subplot?I've saved 4 pictures in 4 variables that means 4 pictures per variable. I'd like to subplot all those pictures (16 pictures) in a loop. Kindly, help me through this.Talha Anwerhttps://ch.mathworks.com/matlabcentral/profile/authors/9402865-talha-anwertag:ch.mathworks.com,2005:Question/4454962019-02-18T03:53:18Z2019-02-18T15:23:30ZLooking for candlestick, rsi, csv file exampleNormally for python and other languages, if i search such keywords candlestick+rsi+csv, i can find plenty of examples.
Now i'm learning matlab, cannot find proper samples yet, so want to start with dummy questions, pls bear with me.
i got this:
Data = readtable('/home/usr1/matlab/spy.csv')
now i want to draw the candlestick and rsi in the same figure, can someone show me a simple code to get started ?
My question is, i don't know the latest correct ways, some examples are from 2011 and won't compile in the latest matlab version.
Thanks !
Ning Jihttps://ch.mathworks.com/matlabcentral/profile/authors/14560433-ning-jitag:ch.mathworks.com,2005:Question/4455942019-02-18T15:22:36Z2019-02-18T15:22:36ZI have the following errorWhen I run the code of PSOGWO to optimize the following function :-
f=norm(gh2b*x(:)-obs,2)+20*Phim;
where :-
r=[58.3095 76.1577 86.0233 98.9949];
r0=mean(r);zx=[30 30 70 70];s=0;
for ii=1:length(r);
s=s+(abs(r(ii)-r0)./4);
end
Phim=s./(zx);
and gh2b is : 12*30 matrix and obs is 12*1 vector
The following error:-
Operands to the || and && operators must be convertible to logical scalar values.
Error in PSOGWO (line 38)
if fitness>Alpha_score && fitness<Beta_score
Error in main (line 25)
[Best_score,Best_pos,PSOGWO_cg_curve]=PSOGWO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
>> M.Shaarawyhttps://ch.mathworks.com/matlabcentral/profile/authors/11317174-m-shaarawytag:ch.mathworks.com,2005:Question/4451732019-02-15T14:58:59Z2019-02-18T15:21:35ZApproximation function in Wavlet-Signal-DenoiserWhat function is used to get the Approximation graph in the Wavlet-Signal-Denoiser app?
More in detail:
When I denoise the signal with a chosen wavelet function, the Wavlet-Signal-Denoiser app visualizes the initial signal, the denoised signal AND an approximation of the denoised signal. When I generate the Matlab skript, I only get the code for the wavlet function but not for the approximation. I would like to code the approximation graph too.Andreas Kauphttps://ch.mathworks.com/matlabcentral/profile/authors/6707322-andreas-kauptag:ch.mathworks.com,2005:Question/4454772019-02-17T23:04:28Z2019-02-18T15:21:16ZSimbiology Sensitivity analysis on dummy variable assigned through a repeatedAssignment RuleHello,
The title pretty much covers my question: I'm trying to use the 'Calculate sensitivities' Task in SimBiology desktop on a dummy variable whose value is enforced through a repeatedAssignment rule in my model, but I get the error:
'An input or output cannot be the left-handside variable of a repeated assignment rule'
I understand what the error is, but I'm wondering if there are any tricks/strategies around this restriction in the sensitivity calculator?
Thanks in advance! Hussein Abdallahhttps://ch.mathworks.com/matlabcentral/profile/authors/13229902-hussein-abdallahtag:ch.mathworks.com,2005:Question/4455932019-02-18T15:20:07Z2019-02-18T15:20:07ZSetting 'Visible' to 'off' in a Panel will stop its child objects from receiving inputs?I have a lot of panels in my GUI. Most of these panels are of same size and have same layout of objects such as text box, edit, popup, etc. Due to large number of these panels, I have implemented a method to scroll through the panels in my GUI. To make a panel go out of visibility I change it's visible property to off but not of any of it's child objects. I am concerned that even when my panel is not visible it's child objects (such as edit box, popup and check box) can receive inputs from mouse or keyboard when I click over it's location.
I tried to find a concrete answer for this question but came out with nothing, I also tried to see if the child objects in the invisible panel reacts to my inputs and it turns out they don't. But I am still not sure, because making a panel invisible by setting it's 'Visible' property to 'off' does't make the 'Visible' property of it's child panels 'off' as well, so why won't they react to my inputs??Chaitanya Jhahttps://ch.mathworks.com/matlabcentral/profile/authors/11993827-chaitanya-jhatag:ch.mathworks.com,2005:Question/4455582019-02-18T12:16:15Z2019-02-18T15:18:45ZIntegration is not evaluated inside a function file Hi
Could you please help with code below. It is not clear to me why the integration does not evaluated inside the function file. when I used script it is worked but I need to simplified the process by creating the func file to call it at different steps. The integration is identified for the variable (b) as presented in the code below:
function Fg=Fg(a)
syms b;
f_UHM=b/(-0.181363336688152-0.637631218835414*b)+2.64004309728928;
diff_f_UHM=diff(f_UHM)
a1=a-2.5;
FF=diff_f_UHM*asin(b/a1)
q1=int(FF,0,a1)
F=subs(f_UHM,a1)
Fg=F-(2/pi)*q1
endWazy skyhttps://ch.mathworks.com/matlabcentral/profile/authors/13323105-wazy-skytag:ch.mathworks.com,2005:Question/4455922019-02-18T15:17:38Z2019-02-18T15:17:38ZHelp optimizing inefficient code I'm relatively new to matlab, and I have a code for merging two datasets based on a common attribute (in this case names). However, my code is very inefficient, so I'd be grateful for any suggestions to make it more efficient.
The gist of it is this: I have two datasets. They have complementary data, and share certain attributes that I'd like to use to combine them. I'm reading Dataset 1 as a cell array. It contains promoters names (which I'll just call promoters), and a value associated with each.
I've been reading Dataset 2 as a table then turning it into cell array. Each row represents one gene, however each gene can possess no promoters, one promoter, or multiple promoters (which I'll just call 'Names' from now on) from dataset 1. I'd like to find a way to append the value in dataset 1 to it's associated identifier as well as gene in dataset 2. In dataset 2, if a gene has multiple promoters they are originally stored in a single string cell and are separated by: ' // '
Essentially:
Dataset 1 (10,000 x 2): 'Name' 'Value' i.e. dataset1= {'Name1', 2.32; 'Name2', 3.42}
Dataset 2 (5000 x 2): 'Gene' 'Name,Name' i.,e. dataset2 = {'Gene1', []; 'Gene2', 'Name1'; 'Gene3', 'Name2 // Name3'}
My solution to this was to split by separator.
for j=[2 3 4 5 6] %dataset2 actually has multiple columns of significance that need splitting, but not important now
for i=1:length(a)
if isempty(a{i,j}) == 1
continue
end
b = char(a{i,j});
c = strsplit(b,' // ');
a{i,j} = [c];
end
end
This converted cells with multiple promoter names into a cell array with promoter names (i.e. {'Gene' 1x3} where the 1x3 is = {'Name1' 'Name2' 'Name3'}.
My solution to merge the data was to use a for loop that assesses the size of that 1x3 cell (that could just be a single name), and search dataset1 for the associated name and append the associated value to dataset 2 in a manner such as:
Dataset 2: {'Gene1', 2x3} where the 2x3 = {'Name1', 'Name2', 'Name3'; 'Value1', Value2', 'Value3'}
Here is my code, I tried to annotate it to make it easier to follow:
for i=1:length(dataset2)
for i=1:length(dataset2)
if isempty(dataset2{i,5}) == 1 % 0 'Names' associated w/ gene
continue
end
s = size(a{i,5});
if s(1,2) == 1 % One 'Name' associated w/ gene
x = a{i,5};
for j=1:length(dataset1)
y = dataset1{j,1};
if strcmp(x,y) == 1 % Using strcmp to find matching 'Names'
a{i,7} = dataset1{j,3};
a{i,8} = dataset1{j,4};
end
end
end
if s(1,2) > 1 % Multiple 'Names' associated with gene
r = a{i,5};
p = 1;
for rr=1:length(s(1,2))
x = r(1,rr);
for m=1:length(dataset1)
y = dataset1{m,1};
if strcmp(x,y) == 1
a{i,7}(2,rr) = dataset1{j,3};
a{i,8}(3,rr) = dataset1{j,4};
end
end
end
end
end
end
I'm sure this is a very convulted script, so any insight would be appreciated.Jack Crowhttps://ch.mathworks.com/matlabcentral/profile/authors/13677523-jack-crowtag:ch.mathworks.com,2005:Question/4453652019-02-17T03:52:31Z2019-02-18T15:08:22ZPlotting trajectory of ballhello,
i’m trying to plot the trajectory of a ball given an initial velocity, height, and angle. i only seem to get a downward trajectory starting at 0. attached is a photo of my code because mathworks wont let me paste my code from my mobile device. any help is appreciated.
Benjamin Merohttps://ch.mathworks.com/matlabcentral/profile/authors/14736437-benjamin-merotag:ch.mathworks.com,2005:Question/4455832019-02-18T14:22:12Z2019-02-18T15:02:46ZHow do I name a graph using a string with probplot?I'm trying to change the title of a probplot graph to a string that is dependent on the parameters calculated in a loop. The code I'm using is
for i = 1:N
fig1 = figure;
plotprob = probplot('lognormal',censoredFailTime,censored,'noref'); % does a lognormal plot of percentage failed over time - parameters have been calculated previously
set(plotprob(1),'Color',[0.5 0 0.5]) % gives colour of graph
grid on
xlabel('Time (h)','FontSize',16)
ylabel('Proportion failed','FontSize',16)
titlestr = strcat('Number of VCSELs = ',num2str(size(data,2)),' Number of failures = ',num2str(NFail)) % calculates the parameters and makes string
title('titlestr') % I want this to show titlestr as the graph title
end
The gives me the error 'index exceeds array bounds' on the title line. titlestr is printed as I want it but it isn't converting to a graph title, what is going wrong?Janna Hinchliffhttps://ch.mathworks.com/matlabcentral/profile/authors/14319116-janna-hinchlifftag:ch.mathworks.com,2005:Question/4455422019-02-18T10:38:03Z2019-02-18T15:01:23ZCompare two or more cell arrays with a specific tolerence?Hi.
I have a cell array with length 3 :
M_t={{[0,1],[0 0 2]},{[0,1.01],[0 0 2]},{[0,1],[0 .001 2]}};
I want to compare these 3 arrays with a specific tolerence. How can i do this?
I have tried intersect before.
Thanks.
Najmeh Eskandarihttps://ch.mathworks.com/matlabcentral/profile/authors/12493981-najmeh-eskandaritag:ch.mathworks.com,2005:Question/4455482019-02-18T05:00:00Z2019-02-18T14:59:09ZHow can I plot a map and calculate distance between two points in the Geographic Space?How can I show a map in a figure? I want the map to be draggable.
How can I calculate the distance between two points in a Geographic Space? I have a longitude and latitude point I want to plot in a map.
MathWorks Support Teamhttps://ch.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:ch.mathworks.com,2005:Question/4455902019-02-18T14:55:46Z2019-02-18T14:55:46ZHow to change .png image to .gif using code or simulink? *if got simulink method is the best*hakim latiphttps://ch.mathworks.com/matlabcentral/profile/authors/11561682-hakim-latiptag:ch.mathworks.com,2005:Question/4455852019-02-18T14:36:38Z2019-02-18T14:54:38ZGetting 'Argument must contain string error' error when saving, it's always worked beforeHere is a short piece of my code.
queue = '\Q0';
Case = '\02';
path = 'D:\Data';
folder4Mfiles = strcat(path,'\Raw',queue,Case); % this corresponds to a location on my computer, I've never had trouble saving with this folder name before
cd(folder4Mfiles)
filename = sprintf('E%d.dat',ti); % Set filename as the E file of current time step
disp('E file is loading') % just what we call the files, they are just .dat format
InputData=load(filename); % Load the E file of current time step
disp('E file is done loading')
M = 352;
N = 92;
P = 352;
X = reshape(InputData(:,1),M,N,P);
save([folder4Mfiles,'\Position_File.mat'],X)
But now I get this error.
Error using save
Argument must contain a string.
I don't understand? [folder4Mfiles,'\Position_File.mat'] is a stringNathaniel H Wernerhttps://ch.mathworks.com/matlabcentral/profile/authors/9280119-nathaniel-h-wernertag:ch.mathworks.com,2005:Question/4455892019-02-18T14:53:48Z2019-02-18T14:53:48Zin my matlab, i have activated it but when i want to run the matlab ,it says to activate it again...what should i do to resolve this??ver
nishad faridhttps://ch.mathworks.com/matlabcentral/profile/authors/14752829-nishad-faridtag:ch.mathworks.com,2005:Question/3202982017-01-13T15:26:40Z2019-02-18T14:53:38ZCombine date vector into single columnI have a n X 6 matrix, with time data:
1st col = yyyy (e.g. 2016)
2nd col = mm (e.g. 10 for Oct)
3rd col = day (e.g. 1)
4th col = hour
5th col = min
6th col = seconds
I need to combine them into a n X 1 (e.g. 1-Oct-2016 00:00:00). How can I do that?
My initial data comes in the form of serial date (e.g. 4.264400001156250e+04 for 1-Oct-2016 00:00:00)
I used this function to convert into a date vector, but am stuck from here:
date_vec = datevec(datestr(x2mdate(raw_data)));
Should I be doing this? My goal is to export to excel for it to be read properly (need to plot a time series). Currently when it goes to the next day, instead of showing up the date of the next day, it simple wraps back to AM of the same day.
e.g.
42644.99999
42644.99999
42645
42645
BenLhttps://ch.mathworks.com/matlabcentral/profile/authors/3963340-benltag:ch.mathworks.com,2005:Question/4455672019-02-18T13:28:14Z2019-02-18T14:53:10ZLooping for calculate parameterHi MATLAB community,
I am trying create a structure to calculate a parameter,
For made this, I would to calculate de a(1)*F(:,1)+a(2)*F(:,2)+a3*F(:,3)......until a(i)*F(i), respectily until that total number of parameters ((i=number of factors), 4 in the case). I have a doubt if I use for or while for this structure.
Could you help me?
Thank you very much
Guilherme Lopes de Campos
correlation=corrcoef(X); % size X(324,19)
eigvalue = eig(correlation);
factor = nnz(eigvalue>=1);% number of factor ( 4 in the case)
nonfactor = nnz(eigvalue<1);
sumeigvalue = sum(eigvalue);
eigvalue = eig(correlation);
[n,j] = size(eigvalue)
for i = 1:n
if eigvalue(i)>=1;
a(i)= eigvalue(i); %obtained the vector of a(i)
end
end
a = sort(a,'descend')
for i=1:factor
parameter = a(i)*F(:,i); % F is a matrix (324,4)
end
Guilherme Guilherme Lopes de Camposhttps://ch.mathworks.com/matlabcentral/profile/authors/8623554-guilherme-lopes-de-campostag:ch.mathworks.com,2005:Question/4455882019-02-18T14:50:49Z2019-02-18T14:50:49ZDesigning a system with script or simulinkI wish to design a system like shown in the figure- in order to observe the curves. Has anyone dealt with something like this?
I don't know from where to start.
I have an equation which I can use with the help of ode solver; but I dont know how to go about it with respect to the system.
Any help would be appreiciated!STPGhttps://ch.mathworks.com/matlabcentral/profile/authors/7060482-stpgtag:ch.mathworks.com,2005:Question/4445452019-02-12T13:54:59Z2019-02-18T14:50:05ZWhy my network is not giving the desired outputI'm trying to design a neural network using nntool of matlab R2015a having input layer of 27 neurons, output layer of 2 neurons and one hidden layer of 10 neurons.I have scaled the input and output data to (0,1) for logsig activation function of hidden layer with purelin in the output layer.For tansig activation function in hidden layer i have scaled the data to (-0.5,0.5). I have trained the network with 1155 training patterns. My mse and R are very good,but the network is not giving the expected result when tested with new data. I have tried almost all the combinations possible from the user inerface(nntool) and in a great confusion. It would be very helpful if answered.
Thank you.vaishnavi potharajuhttps://ch.mathworks.com/matlabcentral/profile/authors/13076403-vaishnavi-potharajutag:ch.mathworks.com,2005:Question/3917332018-03-30T22:09:04Z2019-02-18T14:48:45ZHow do I separate date and time of a raw date? >> a = untitled.startDate(1:10)
a =
10×1 categorical array
2013-07-10 00:01:00.0
2013-07-17 00:01:00.0
2013-06-29 00:01:00.0
2013-07-17 00:01:00.0
2013-05-11 00:01:00.0
2013-05-31 00:01:00.0
2013-06-06 00:01:00.0
2013-08-31 00:01:00.0
2013-05-21 00:01:00.0
2013-08-06 00:01:00.0
>> a.Format = 'dd-MMM-yyyy'
Error using categorical/subsasgn (line 87)
Attempt to assign field of non-structure array.aishahhttps://ch.mathworks.com/matlabcentral/profile/authors/10462330-aishahtag:ch.mathworks.com,2005:Question/4455682019-02-18T13:29:59Z2019-02-18T14:46:53Zlicence on virtual machineHello everybody,
I will use matlab for an industrial project that will be installed on a virtual machine.
Before deploying the server we will do some test on a different machine (and maybe different VM) in order to validate the model.
My question is can we do that with only one licence using it for the test and then in production.
BR Romain CAILLIEREhttps://ch.mathworks.com/matlabcentral/profile/authors/12702116-romain-caillieretag:ch.mathworks.com,2005:Question/4455102019-02-18T05:41:11Z2019-02-18T14:46:33ZHow to store each logical linear array in a matrix?clc;
close all;
clear;
workspace;
folder = 'D:\data_set';
filepattern = fullfile(folder, '*.png');
srcFiles = dir(filepattern);
numImages = length(srcFiles);
t=0:0.001:2*pi;
for k = 1 : numImages
fullFileName = fullfile(folder, srcFiles(k).name);
a = imread(fullFileName);
bwimg =bwareafilt(~a, 1);
s=regionprops(bwimg,'Orientation');
theta = s.Orientation;
if theta>=0 && theta<90
phi=90-theta;
Y=imrotate(bwimg,phi);
else
phi=90-(-theta);
Y=imrotate(bwimg,-phi);
end
s1=regionprops(Y,'Centroid','BoundingBox','MajorAxisLength','MinorAxisLength','Area');
Area = [s1.Area];
index = find(Area==max(Area));
circleCenterX = s1(index).Centroid(1);
circleCenterY= s1(index).Centroid(2);
diameters = mean([s1(index).MajorAxisLength s1(index).MinorAxisLength],2);
r1 =1*diameters/16;
r2=2*diameters/16;
r3=3*diameters/16;
r4=4*diameters/16;
r5=5*diameters/16;
r6=6*diameters/16;
r7=7*diameters/16;
r8=8*diameters/16;
r9 =9*diameters/16;
r10=10*diameters/16;
r11=11*diameters/16;
r12=12*diameters/16;
r13=13*diameters/16;
r14=14*diameters/16;
r15=15*diameters/16;
r16=16*diameters/16;
radii=[r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16];
[g,h]=size(radii);
[r,c]=size(Y);
bw=false(r,c);
for j=1:h
thisRadius = radii(1, j);
x = circleCenterX + thisRadius * sin(t);
y = circleCenterY + thisRadius * cos(t);
bw = bw|poly2mask(x,y,r,c);
boundaries = bwboundaries(bw);
thisBoundary = boundaries{1};
x1=thisBoundary(:,2);
y1=thisBoundary(:,1);
indexes = y1<circleCenterY; % Only those in the upper half.
xTop = x1(indexes);
yTop = y1(indexes);
for l=1:length(xTop )
profile(l) = Y(yTop(l),xTop(l));
A{k,j}=profile;
end
end
end
For each image in the dataset I am repeating the same procedure. But unable to store different length profile. For First image its ok. But for other images A{k,j}=profile storing the same length profiles although their radius is different . How to resolve this ? Zara Khanhttps://ch.mathworks.com/matlabcentral/profile/authors/10893209-zara-khantag:ch.mathworks.com,2005:Question/4390472019-01-09T21:38:50Z2019-02-18T14:43:57ZHow to auto-generate the test cases using Simulink Design Verifier on a huge model which has unit models inside it. How can i avoid the error active configuration cannot be changed in compilation or simulation? As per the process I have been using this Simulink design Verifier for auto generating the test cases. When I am trying to do on the HVAC module which has 20 to 25 unit models assigned to it. I am supposed to generate the test cases for the huge model which has 324 inputs and 171 outputs. Inside the HVAC module, there are many unit models which are like a reference to this huge model.
I would like to avaoid an error which is relating to the active configuration changes are not done while compilation or simulation. The stop mentioned is "inf". I have checked the configuration pane and changed the process accordingly. There is one more issue is that, when I am trying to correct the error and trie to rebuild the process, it wont start again. The error dialog box says that there is one unit model which is compiling or simulating mode.
I would like to know is their anything that I can avoid the errors to do my work.Kameswari Vemurihttps://ch.mathworks.com/matlabcentral/profile/authors/13974928-kameswari-vemuritag:ch.mathworks.com,2005:Question/4451052019-02-15T08:14:12Z2019-02-18T14:43:26ZResizing pixels with independent scaling factor?How can be pixels resized with independent scaling factor?
Keeping size of final image same as initial image.
e.g.
+ =
Resizing method 'nearest' would be enough.
Right I am using some kind of 'for' loop but want to avoid it for faster processing.
Starting experiment data could be:
%% Creation of starting image
w=8;
im=255*ones(w,w,1, 'uint8');
im(2,2,:)=0;
im(6,6,:)=0;
%% Inputs to resize pixels
row=[2;6]; col=[2;6];
scale=[3;5]; % length of each of these inputs are same, explanation: pixel{2,2} will have a scaling factor 3 and so on..
% fractional scaling factor can be entertained as per nearest resizing method.
% length of these inputs are large, of the order of number of pixels in the image, thats why for loop takes time.
Any innovative ideas are welcome
Note: During resizing process sometimes pixels may overlap, in this case, new values will overwrite the old values
i.e., pixels processed due to bottom values of [row, col & scale] can overwrite the previous values.
ThanksJAI PRAKASHhttps://ch.mathworks.com/matlabcentral/profile/authors/7172030-jai-prakashtag:ch.mathworks.com,2005:Question/2443042015-09-21T16:40:27Z2019-02-18T14:42:50ZGenerate random 3D coordinates in a cylinderI want to generate a set of 1000 3D points (x,y,z) which are located inside a cylinder of radius r and centre axis from [x1,y1,z1] to [x2,y2,z2].
Any ideas?
Lucyhttps://ch.mathworks.com/matlabcentral/profile/authors/3740138-lucy