https://fr.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-03-01T01:48:20Ztag:fr.mathworks.com,2005:Question/7589442021-03-01T01:48:20Z2021-03-01T01:48:20ZHow to write for or while loop along with indexing?Hello Sirs
May I ask your guidance for my study please?
There are three data in my problem (1) months and (2) Demand (3) X for several years.
I need to specify the first X value as SWA and second X value as EWA and third value as HF.
In this sample excel file 2 years data is given. Thus, there will be two SWA, two EWA and two HF.
Then, I need to mulitply the every 12 months Demand data with specific SWA, EWA and HF.
First SWA value (0.0319) should mulitply the demand 1:12 and second SWA value (0.9873) should multiply the demand 13:24 and so on.
First EWA (0.5272) should mulitply with constant value K= 1000 and plus with demand 1:12. Similarly, second EWA (0.0028) should multiply with K=1000 and plus the demand data from 13:24.
%input
clear all;
data=xlsread('data.xlsx');
demand=data(1:24,2);
x=data(1:6,3);
K=1000;
% I used incrementing by 3 to get the SWA , EWA and HF index and value.
SWA_idx=[1:3:6]';SWA_x=x(SWA_idx);
EWA_idx=[2:3:6];EWAx=x(EWA_idx);
HF_idx=3:3:6;HF=x(HF_idx);
%I select demand indexing for months and multiply with relevant SWA value.
y1=demand(1:12).*SWA_x(1);
y2=demand(13:24).*SWA_x(2);
z1=(1:12)+K*EWAx(1);
z2=(13:24)+K*EWAx(2);
%Now, I have to change everything sentence manually and it is very painful task for many years.
% So I want to use for loop or while loop. But, I don't know how to do it and can you kindly guide me please?
% Thank you very much.
soe thihahttps://fr.mathworks.com/matlabcentral/profile/authors/13030378tag:fr.mathworks.com,2005:Question/7589292021-03-01T01:34:16Z2021-03-01T01:48:08ZHow to append values from different files to an array?Hello, I have a script that reads in a signal and finds the mean intensity from it. I have hundreds of these files and each time I run I would like to add the next mean value to an array. The files are CSV's and the code is edited each time to call a new file.
data=load('600-0.csv'); %filename changed every time and ran again
V=data(:,1);
M=mean(V);
% I have tried using this, however this overwrites each time.
mean=[]
mean = [mean; M]
Thank you for help. I have spent a lot of time trying to find a solution before posting here.Fraser Barnardhttps://fr.mathworks.com/matlabcentral/profile/authors/13802309tag:fr.mathworks.com,2005:Question/7589392021-03-01T01:47:14Z2021-03-01T01:47:14ZProblem with imresize functionHeres my code, I wasnt having an issue with this until i added the midterm function and all the parameters. When i hardcoded the pictures and numbers i needed it worked perfectly but now it keeps giving me an error on line 3. Im really new to matlab and I dont have an prior programming knowlege so im just generally confused here. Any help?
function [] = midterm(imageFile1,imageFile2, scale, margin)
IM2 = imresize(imageFile2, scale);
IM2(1:margin,:,:) = 255;
IM2(end-margin+1:end,:,:) = 255;
IM2(:,1:margin,:) = 255;
IM2(:,end-margin+1:end,:) = 255;
image(imageFile1)
hold on;
image(2337, 1000, IM2)
endElliot Wylliehttps://fr.mathworks.com/matlabcentral/profile/authors/19236801tag:fr.mathworks.com,2005:Question/7589042021-03-01T00:51:20Z2021-03-01T01:43:10ZHelp using symbolic transfer functionI'm trying to use the feedback function to determine the closed loop transfer function of a given system. The system has two variables K1 and K2. The 'G' in the feedback function would be: . I read a ton of posts on here stating that you can't use symbolic variables in the tf function, but I didn't see any one mention a way around it. Here is my code:
syms K1
syms K2
K = 6;
G = tf([K1*K2], [1 -3 -4]);
H1 = feedback(G,K);Mark Cornellhttps://fr.mathworks.com/matlabcentral/profile/authors/16673915tag:fr.mathworks.com,2005:Question/3122182016-11-14T21:04:18Z2021-03-01T01:42:46ZMethods to get ride of Root in solution of solve function<https://www.mathworks.com/matlabcentral/answers/282911-root-in-answer-of-solve-function Related Question>
<- This link shows a related question. I do not understand the accepted solution. I tried to copy and paste using R2016b and exprc was unknown. I tried to replace exprc with orig_expression but the output was still just the root functions.
The solve equation below is taking forever. Solve(...,v_3) (without out 'real' flag) returns 6 root functions. I'm looking for an answer that is only a function of a_1,v_1,A,D.
solve(S == (D*(((A + D)*(a_1^2 - 2*A*v_1 + 2*A*v_3))/D)^(3/2))/(3*(A + D)^3) - (a_1 - (D*(((A + D)*(a_1^2 - 2*A*v_1 + 2*A*v_3))/D)^(1/2))/(A + D))^3/(6*A^2) - (D*(((8*v_3*A^2 + D)/D)^(1/2) - 1)^2)/(8*A^3) - (v_1*(a_1 - (D*(((A + D)*(a_1^2 - 2*A*v_1 + 2*A*v_3))/D)^(1/2))/(A + D)))/A + ((((A + D)*(a_1^2 - 2*A*v_1 + 2*A*v_3))/D)^(1/2)*(- a_1^2 + 2*A*v_1 + 2*D*v_3))/(2*(A + D)^2) + (a_1*(a_1 - (D*(((A + D)*(a_1^2 - 2*A*v_1 + 2*A*v_3))/D)^(1/2))/(A + D))^2)/(2*A^2) + (v_3*(((8*v_3*A^2 + D)/D)^(1/2) - 1)*(A + D))/(2*A^2) - (D*(2*A^2 + D^2)*(((8*v_3*A^2 + D)/D)^(1/2) - 1)^3)/(16*A^5), v_3, 'Real', true)
An Nguyenhttps://fr.mathworks.com/matlabcentral/profile/authors/7710844tag:fr.mathworks.com,2005:Question/2829112016-05-06T13:00:29Z2021-03-01T01:41:30ZRoot() in answer of solve functionHello, I am solving a partial derivative equation using symbolic expression. After using f1= diff(f,Qs) and solve(f1,Qs), I got the following answer that have root(....). Anybody can explain to me how can I get rid of root()?
Note: z is not defined initially
Thanks for your help
Example:ans= root(3*a^2*k^2*z^6 - 2*Qn*a^2*k^2*z^5 + 4*a*k*z^5 - 3*Qn^2*a^2*k^2*z^4 + 8*Qn*a*k*z^4,z,1) Linh Danghttps://fr.mathworks.com/matlabcentral/profile/authors/5040812tag:fr.mathworks.com,2005:Question/5415682020-06-03T18:18:37Z2021-03-01T01:40:47ZNested tables with duplicate sub-column names?I'm trying to create a table that consists of two sub-tables, with different names, each of which is two columns wide. All four sub-columns have the same number of rows. The issue is that the first sub-column in both sub-tables has the same name, and ditto for the second:
----- START ----- ----- STOP -----
Week Seconds Week Seconds
1234 567890 1234 604799
1235 123450 1235 271828
When I try to nest this into a single table, as shown a few of the examples here, I keep getting "Duplicate table variable name: 'Week'."
Of course I could rename the columns as something like "WeekStart", "SecondsStart", etc. to avoid this, but that's a bit awkward—in that case I'd just make a single four-column table, but would lose the nice grouping in the process. I've tried a few of the examples above, as well as mergevars and splitvars, but no luck so far.
Is there a clean way to do this, or is this just not how MATLAB tables are meant to be used? AMMhttps://fr.mathworks.com/matlabcentral/profile/authors/18123668tag:fr.mathworks.com,2005:Question/7589342021-03-01T01:38:59Z2021-03-01T01:38:59ZOptimize the constant by minimizing the error whit no direct relationI want to find the optimised value for the three constant C1, C2, C3 by minimising the error of ErFEM.
I run an ABAQUS job; in the first job, I define C1, C2, C3, and the ABAQUS generates a result, let's name it FEMresutl.
I subtract the FEMresult from the gold standard, and the final result is ErFEM.
ErFEM should become less than 50um by optimising C1, C2, C3.
However, there is no direct relation between the ErFEM and C1, C2, and C3.
How can I write an optimisation code that optimises the C1, C2, C3 by minimising the ErFEM?
ThanksSMhttps://fr.mathworks.com/matlabcentral/profile/authors/10908668tag:fr.mathworks.com,2005:Question/7587342021-02-28T18:16:14Z2021-03-01T01:37:57Zhow to share the data from one app to another app in matlab app designer I know this question already asked I also going to refference document but the concept is not cleard to me.
please help me to reach out. I explained below what I want.
I have User input promt on which i taken the input as temperature value in 3 numeric EditFeild.
share that 3 numeric edit feild value to another app where another 3 numeric EditField in that I want to show average of all the temperature, maximum and minimum temperature among three .
I have added 1st button to open the 2nd app and 2nd button to get the result in other app.
I think this enough to clear the concept how to share the data from one app to another.
please suggest code for it thank you! Krutik Gujarathihttps://fr.mathworks.com/matlabcentral/profile/authors/18541524tag:fr.mathworks.com,2005:Question/3108152016-11-05T22:12:46Z2021-03-01T01:36:31ZSpecify annotation position with respect to x- and y-axes values? Dear all,
Is there a way the define the starting and end point of an annotation object such as an arrow in terms of the data being plotted and not as either "normalized" coordinates (x- and y-positions between 0 and 1) or a physical length measurement such as cm?
E.g. I am plotting a time from 0 to 180 s on the x-axis and a concentration between 0 and 0.1 concentration units on the y-axis. Now I would like to draw an arrow starting at 90 s, 0.04 concentration units and going to 120 s, 0.09 concentration units.
I have already considered to simply "normalize" those positions myself (e.g. 90 s/180 s = 0.5 --> x-position in normalized coordinates). This does, however, not work, since 0 and 1 refer to points in the whole figure (the window in which the plot appears) and not to the area of the plot itself.
Thanks for any input!
ClemensClemenshttps://fr.mathworks.com/matlabcentral/profile/authors/8274735tag:fr.mathworks.com,2005:Question/4636372019-05-23T10:55:07Z2021-03-01T01:32:31ZWarning "Ignoring extra legend entries"Hi everyone,
so this is my code, sorry if it distracts you, please let me know.Just put the code so that everyone knows excactly what is my question. Please just scroll down to read my questions, and use the code for solving it.
%% variable declaration
colours = 'rbk';
%% Solve ODEs using Euler's method
figure(4) %figure 4
%Input
y0 = 1;
z0 = 1;
u = 1;
tspan = [0 30];
%two first order ODE
dydt = @(t,z) z;
dzdt = @(y,z) u*(1-y^2)*z - y;
% solving ODE for each h value
%Creating vector h
h = [0.25,0.125,0.0625];
%forming a matrice of cells since each variables has different size
t_e=cell(1,length(h));
y_e=cell(1,length(h));
z_e=cell(1,length(h));
%Solving ODE for each h value
for i = 1:length(h)
[t_e{i},y_e{i},z_e{i}] = euler2(dydt,dzdt,tspan,y0,z0,h(i));
end
%plotting
for i = 1:length(h)
subplot(2,1,1)
hold on
plot(t_e{1,i},y_e{i},colours(i));
xlabel('t')
ylabel('y')
title('y against t')
legend('step size = 0.25','step size = 0.125','step size = 0.0625','Location','nw')
subplot(2,1,2)
plot(t_e{1,i},dydt(t_e{1,i},z_e{1,i}),colours(i));
hold on
xlabel('t')
ylabel('dydt')
title('dydt against x')
legend('step size = 0.25','step size = 0.125','step size = 0.0625','Location','nw')
end
%print the method that increase the accuracy
fprintf('The accuracy of the solutions can be improved by \nreducing the step size of h, as it can be seen in the graph')
%function file
if ~(tspan(2)>tspan(1))
error('upper limit must be greater than lower')
end
% Create all independent values, t
%use tspan to create a vector with spacing = h;
t = [tspan(1):h:tspan(2)]';
n = length(t);
if t(end) < tspan(2)
t(n+1) = tspan(2);
n = n+1;
end
% add extra t-value if needed
%check if final t-value can be achieved using the current h
%if not, add a new t-value to the end of t
% Implement Euler's method
%use a for loop
%pre allocate the solution vector
%y = zeros(1,n)
%z = zeros(1,n)
%y(1) = y0
%z(1) = z0
y = y0*ones(n,1);
z = z0*ones(n,1); % 1 line
for i = 1:n-1 %stop at n-1 because dont need to calculate the deriative for final interation
%singeline for euler's method
z(i+1) = z(i) + h*dzdt(y(i),z(i));
y(i+1) = y(i) + h*z(i);
end
%%%% Question
When i run this code, it gives me the error
So I do not know why it gives me that .Can someone explain, and any methods to solve it ?
Thanks in advance,
Khang
Khang Nguyenhttps://fr.mathworks.com/matlabcentral/profile/authors/14922118tag:fr.mathworks.com,2005:Question/7589242021-03-01T01:30:22Z2021-03-01T01:30:22ZMaking a function to plot SVD Write a Matlab function that, given a real 2×2 matrixAand a figure id, plots the right singularvectorsv1andv2and the unit circle in one subplot and the left singular vectorsu1andu2and thecorresponding ellipse in another subplot
Here is the basic outline of the code that i do have.
function plot_svd(A, figId)
Step 1: calc and plot the SVD of A
figure(figId)
subplot(1, 2, 1)
subplot(1, 2, 2)
Step 2: plot the unit circle and the corresponding ellipses
figure(figId)
subplot(1, 2, 1)
hold on;
subplot(1, 2, 2)
I really need help. Larry Ellisonhttps://fr.mathworks.com/matlabcentral/profile/authors/13990361tag:fr.mathworks.com,2005:Question/7555042021-02-25T02:41:13Z2021-03-01T01:27:07ZHow to draw bar graph of different colors ?I have plotted the bar graph but the color is same. i want to differentiate the color of each x variable .Thank you in advance !DEWDROPhttps://fr.mathworks.com/matlabcentral/profile/authors/17087369tag:fr.mathworks.com,2005:Question/7588942021-03-01T00:45:27Z2021-03-01T01:15:00ZHow can I send real-time COM port data to a MATLAB instance hosted on a server?This is a tricky one. I've created a device that sends commands to my computer through a USB connection. I've written a program in MATLAB that uses the inputs originating from the device by reading them off the COM port. When running MATLAB on my own computer there is no problem. For other people working with me, we bought a floating license and simply install MATLAB on each of our computers. This setup gives us direct access to the COM data from the device.
The problem: I want to demonstrate my device and accompanying software to people outside our group, and I want to avoid asking them to install MATLAB and figure out connecting ports.
To solve this, I purchased a MATLAB license that I've placed on a server. My hope was that I could give my physical device to people and they could demo the software over the server without having to go through the process of installing MATLAB and connecting ports, etc. I can connect to the server, but I can't figure out how to send COM port data to the server where it can be read by MATLAB. The data is meant to be live.
How can I send real-time COM port data to a MATLAB instance hosted on a server?MaxThttps://fr.mathworks.com/matlabcentral/profile/authors/19314496tag:fr.mathworks.com,2005:Question/7498442021-02-19T03:38:29Z2021-03-01T01:05:35ZHELP lotto game??(please)Hello Im trying to create a lotto game. ; the lotto game consists of picking 9 different numbers from 1 to 100 and placing them in a matrix. Subsequently, a series of random multiplications of 2 numbers , for example: 2X5, 7X8, 1x1. The result of the multiplications (example in this case 10, 56, 1) are the numbers that the player will look for in his matrix. The first player to get the 9 matches between the results of the multiplications and the numbers in his matrix is the winner.
But its not working. I really apreciatte your help!
disp('Welcome lotto game');
tx0='¿Wanna play? yes//no >>';
a1=input(tx0,'s');
while strcmpi(a1,'yes') || strcmpi(a1,'y')
tx2='\n Press #1 to star \n';
rb=input(tx2);
switch rb
case 1
fprintf('\n Write a matrix 3x3 with numbers 1 to 100 >>\n ');
tx='>>';
n1= input(tx);
n2= input(tx);
n3= input(tx);
n4= input(tx);
n5= input(tx);
n6= input(tx);
n7= input(tx);
n8= input(tx);
n9= input(tx);
nx= [n1 n2 n3; n4 n5 n6; n7 n8 n9 ];
t='Matrix is ';
disp(t);
disp(nx);
rt=input(nx);
rt1=lottery(rt);
an1=sprintf('Coincidences are : %g ',rt1);
disp(an1)
otherwise
disp('game over');
end
%% and the function is ::
function x=lottery(input)
n0=100;
for ibi=1:n0
x=randi([0 10 ],3,3)*input;
end
disp(x)
r=x.*input;
matriz=(m==r);
disp('Matrix given from lotto game: ');
disp(r);
disp(matriz);
endBlue Matloverhttps://fr.mathworks.com/matlabcentral/profile/authors/21538876tag:fr.mathworks.com,2005:Question/7589192021-03-01T00:58:16Z2021-03-01T00:59:15ZHow to reconcile PTBs 'GetSecs' with Matlab's 'now'?Hello! I inherited some task code that uses Psychtoolbox (PTB) to show various images on a screen during an fMRI experiment. The synchronization of the MRI data with the stimulus presentation is handled by a single pulse from the scanner. The pulse is recorded using PTB's KbWait function. After that the onset times of all blocks are recorded via writing the 'now' value to a logfile. The now value can be converted to a datetime object and read out - though PTB's KbWait relies on GetSecs which as far as I know returns the value (in seconds, with precision) from the time of system startup.
Is there any way for me to get these two sets of values into the same format? I don't know when the system started up that day so the value returned by GetSecs seems useless? Any help would be appreciated if I can't sync the data to stimulus I'll have to throw away this dataset :(
I am using 2020b, the task was carried out using 2017a
Further Information:
The pulse time returned by GetSecs = 1.163322498366500e+06
A stimON value in the log file = 7.382064341012850e+14Varun Wadiahttps://fr.mathworks.com/matlabcentral/profile/authors/11080584tag:fr.mathworks.com,2005:Question/7589142021-03-01T00:53:15Z2021-03-01T00:53:15ZHow to plot a streaklineplot the streakline of this flow taken at t=0 V=u0sin(w(t-y/v0)i + v0j
u0, v0, and w are constants therefore v=v0
x component of the velocity at y=0 conincides with the velocity of the oscillating sprinkler head [u=u0 sin(wt) at y=0Richard Krausehttps://fr.mathworks.com/matlabcentral/profile/authors/13528042tag:fr.mathworks.com,2005:Question/7541792021-02-23T19:20:38Z2021-03-01T00:52:56ZLogical with complex numbers in a vectorI have a complex number in a vector,
e =
-0.0000
3.0000
9.0000
>> logical(e) %checking if the the first entry is actually 0. Results show it is not
ans =
3×1 logical array
1
1
1
>> t = sqrt(e) % sqauring the entries shows all the three entries are complex numbers
t =
0.0000 + 0.0000i
1.7321 + 0.0000i
3.0000 + 0.0000i
L = logical(t) % In Matlab documentation it not possible to use logical for complex numbers
Error using logical
Complex values cannot be converted to logicals.
>> t(1,1)==0 % checking if the first entry is actually 0?
ans =
logical
0
>> t(1,1)<0 % checking if the first entry is actually less than 0?
ans =
logical
0
>> t(1,1)>0 % checking if the first entry is actually greater than 0?
ans =
logical
0
% QUESTION: is there a way to compare t(1,1) with 0 to know whether is it 0 or not?
% Alternatively: What is the genral way of using logicals for complex numbers?salam mahamahttps://fr.mathworks.com/matlabcentral/profile/authors/4478798tag:fr.mathworks.com,2005:Question/7589092021-03-01T00:52:43Z2021-03-01T00:52:43ZAlign two coordinate frames (boresight error correction)Just a little background: I have a drone and a lidar, and the lidar has a fixed position relative to the drone. I'm trying to correct the boresight error between lidar and IMU of the drone (I'm not even considering lever arm error at this point since I can't figure out how to correct boresight error in the first place, and my data were collected indoors so I don't have GPS data available).
I have two point clouds pc1 and pc2 and corresponding quaternion outputs q1 and q2 from drone in wxyz format (q1 = [0.195161, 0.094749, 0.118611, -0.96895], q2 = [0.2138, 0.100426, 0.116502, -0.96469]). I am able to register pc1 and pc2 using a function such as pcregistericp with pc2 being fixed and pc1 being moving, and obtain the rotation matrix r (r = [0.998824, -0.04842, 0.002445; 0.048378, 0.998719, 0.014863; -0.00316, -0.01473, 0.999887]). I thought using q1, q2 and r I should be able to somehow estimate boresight error between drone and lidar and further use that information to align lidar's coordinate frame with drone's coordinate frame (both are right-handed) regardless of lidar's orientation relative to the drone.
Due to my lack of knowledge, even after tons of experiements I still couldn't figure out the right math to align the two frames (I'll skip my own calculations). So my question is given q1, q2 and r, how to align lidar's frame to drone's frame?Wenhttps://fr.mathworks.com/matlabcentral/profile/authors/16266766tag:fr.mathworks.com,2005:Question/7588992021-03-01T00:46:54Z2021-03-01T00:46:54Zsolving integral equation where the unknow is the upper limitI have this function
function H = ICPH(T0,T,A,B,C,D)
syms x
f(x) = A+B*x+C*x^2+D*x^(-2);
H = int(f(x),x,T0,T);
end
this function work fine if I put all numerical values
example
y =8.314* ICPH(298.15, 2066, 43.471, 9.502e-3, 0.0, -0.645e5);
vpa(y,6)
ans
802482.0
however if I put this code
syms T real
g = 802482.0 == 8.314* ICPH(298.15, T, 43.471, 9.502e-3, 0.0, -0.645e5);
h5 = vpa(solve(g,T),6)
h5 = 0.585853
In the above code I was trying to solve for the T.
If I enter T manually i got the right answer put I use solve to find the unknow temperature the answer dont make sence.
h5 should be 2066.
what im doing wrongAhmed Hassanhttps://fr.mathworks.com/matlabcentral/profile/authors/12026972tag:fr.mathworks.com,2005:Question/7558692021-02-25T11:48:05Z2021-03-01T00:39:34ZHow can I allow the user to choose what to do?Hello everyone!!
I have a main forder D:\ABIDEdataset\Outputs\dparsf\nofilt_noglobal\rois_aal with 16 subfolders (ie Stanford, KKI, Leuven, Trinity, etc...). With this code below I perform 6 different calculations (Correlation, h2, mutual information, transfer entropy, coherence and granger) for all the subjects present in all subfolders and then save these matrices generated.
But, I came up with the idea of letting the user choose which metric to analyze (and the option to analyze all) and for which subfolder... Can anyone give me some help in this?
%% Load files from main folder subfolders
dinfo = dir('D:\ABIDEdataset\Outputs\dparsf\nofilt_noglobal\rois_aal\**\*.mat');
filenames = fullfile({dinfo.folder}, {dinfo.name});
numfiles = length(filenames);
vect_NumberSubjs = [15 23 24 33 36 36 37 39 41 44 48 59 61 75 113 169];
vect_TR = [repelem(2,37) repelem(2.5,39) repelem(1.6,59) repelem(3,41) repelem(2,169) repelem(2.5,23) repelem(1.5,24) repelem(1.5,36) repelem(2.2,15) repelem(2,33) repelem(2,36) repelem(2,44) repelem(3,75) repelem(2,113) repelem(2,61) repelem(2,48)];
NumberSubjs = sum(vect_NumberSubjs);
%% Parameters for metrics
modelOrder = 2;
bins = 2;
params = struct('MaxDelay', 10, 'bins', 10);
maxlag = 10;
freq_min = 0.01;
freq_max = 0.08;
freqs = [freq_min freq_max];
%% Store each metric in the respective matrix
FC_CorrelationMatrix_BCorrD = zeros(116,116,NumberSubjs);
FC_CorrelationMatrix_BCorrU = zeros(116,116,NumberSubjs);
FC_CorrelationMatrix_PCorrD = zeros(116,116,NumberSubjs);
FC_CorrelationMatrix_PCorrU = zeros(116,116,NumberSubjs);
FC_h2Matrix_BH2D = zeros(116,116,NumberSubjs);
FC_h2Matrix_BH2U = zeros(116,116,NumberSubjs);
FC_h2Matrix_PH2D = zeros(116,116,NumberSubjs);
FC_h2Matrix_PH2U = zeros(116,116,NumberSubjs);
FC_MIMatrix_BMITD1 = zeros(116,116,NumberSubjs);
FC_MIMatrix_BMITD2 = zeros(116,116,NumberSubjs);
FC_MIMatrix_PMITD1 = zeros(116,116,NumberSubjs);
FC_MIMatrix_PMITD2 = zeros(116,116,NumberSubjs);
FC_MIMatrix_BMITU = zeros(116,116,NumberSubjs);
FC_MIMatrix_PMITU = zeros(116,116,NumberSubjs);
FC_TEMatrix_BTED = zeros(116,116,NumberSubjs);
FC_TEMatrix_BTEU = zeros(116,116,NumberSubjs);
FC_TEMatrix_PTED = zeros(116,116,NumberSubjs);
FC_TEMatrix_PTEU = zeros(116,116,NumberSubjs);
FC_CohMatrix_BCohF1 = zeros(116,116,NumberSubjs);
FC_CohMatrix_BCohF2 = zeros(116,116,NumberSubjs);
FC_CohMatrix_BCohW1 = zeros(116,116,NumberSubjs);
FC_CohMatrix_BCohW2 = zeros(116,116,NumberSubjs);
FC_CohMatrix_PCohF1 = zeros(116,116,NumberSubjs);
FC_CohMatrix_PCohF2 = zeros(116,116,NumberSubjs);
FC_CohMatrix_PCohW1 = zeros(116,116,NumberSubjs);
FC_CohMatrix_PCohW2 = zeros(116,116,NumberSubjs);
FC_GCMatrix_GC = zeros(116,116,NumberSubjs);
FC_GCMatrix_PGC = zeros(116,116,NumberSubjs);
FC_GCMatrix_CondGC= zeros(116,116,NumberSubjs);
%% Calculate metrics
for i=1:numfiles
thisfile = filenames{i};
thisfile_cell = struct2cell(load(thisfile));
lfp = transpose(thisfile_cell{1}); % it's always changing
TR = vect_TR(i); % it changes for every subfolder
fs = 1/TR;
Corr_Methods = mln_icalcMatTimeBasic(lfp,modelOrder);
FC_CorrelationMatrix_BCorrD(:,:,i) = Corr_Methods.BCorrD;
FC_CorrelationMatrix_BCorrU(:,:,i) = Corr_Methods.BCorrU;
FC_CorrelationMatrix_PCorrD(:,:,i) = Corr_Methods.PCorrD;
FC_CorrelationMatrix_PCorrU(:,:,i) = Corr_Methods.PCorrU;
h2_Methods = mln_icalcMatH2(lfp,modelOrder,bins);
FC_h2Matrix_BH2D(:,:,i) = h2_Methods.BH2D;
FC_h2Matrix_BH2U(:,:,i) = h2_Methods.BH2U;
FC_h2Matrix_PH2D(:,:,i) = h2_Methods.PH2D;
FC_h2Matrix_PH2U(:,:,i) = h2_Methods.PH2U;
MI_Methods = mln_icalcMatMITime(lfp,params);
FC_MIMatrix_BMITD1(:,:,i) = MI_Methods.BMITD1;
FC_MIMatrix_BMITD2(:,:,i) = MI_Methods.BMITD2;
FC_MIMatrix_PMITD1(:,:,i) = MI_Methods.PMITD1;
FC_MIMatrix_PMITD2(:,:,i) = MI_Methods.PMITD2;
FC_MIMatrix_BMITU(:,:,i) = MI_Methods.BMITU;
FC_MIMatrix_PMITU(:,:,i) = MI_Methods.PMITU;
TE_Methods = mln_icalcMatTE(lfp,maxlag);
FC_TEMatrix_BTED(:,:,i) = TE_Methods.BTED;
FC_TEMatrix_BTEU(:,:,i) = TE_Methods.BTEU;
FC_TEMatrix_PTED(:,:,i) = TE_Methods.PTED;
FC_TEMatrix_PTEU(:,:,i) = TE_Methods.PTEU;
Coh_Methods = mln_icalcMatFreqBasic(lfp,freqs,fs);
FC_CohMatrix_BCohF1(:,:,i) = Coh_Methods.BCohF(:,:,1);
FC_CohMatrix_BCohF2(:,:,i) = Coh_Methods.BCohF(:,:,2);
FC_CohMatrix_BCohW1(:,:,i) = Coh_Methods.BCohW(:,:,1);
FC_CohMatrix_BCohW2(:,:,i) = Coh_Methods.BCohW(:,:,2);
FC_CohMatrix_PCohF1(:,:,i) = Coh_Methods.PCohF(:,:,1);
FC_CohMatrix_PCohF2(:,:,i) = Coh_Methods.PCohF(:,:,2);
FC_CohMatrix_PCohW1(:,:,i) = Coh_Methods.PCohW(:,:,1);
FC_CohMatrix_PCohW2(:,:,i) = Coh_Methods.PCohW(:,:,2);
GC_Methods = mln_icalcMatGranger(lfp,modelOrder);
FC_GCMatrix_GC(:,:,i) = GC_Methods.GC;
FC_GCMatrix_PGC(:,:,i) = GC_Methods.PGC;
FC_GCMatrix_CondGC(:,:,i) = GC_Methods.CondGC;
end
%% Store the results
MatricesCalculationDir = 'D:\ABIDEdataset\Outputs\dparsf\nofilt_noglobal\rois_aal';
save(fullfile(MatricesCalculationDir, 'FC_CorrelationMatrix_BCorrD'), 'FC_CorrelationMatrix_BCorrD');
save(fullfile(MatricesCalculationDir, 'FC_CorrelationMatrix_BCorrU'), 'FC_CorrelationMatrix_BCorrU');
save(fullfile(MatricesCalculationDir, 'FC_CorrelationMatrix_PCorrD'), 'FC_CorrelationMatrix_PCorrD');
save(fullfile(MatricesCalculationDir, 'FC_CorrelationMatrix_PCorr U'), 'FC_CorrelationMatrix_PCorrU');
save(fullfile(MatricesCalculationDir, 'FC_h2Matrix_BH2D'), 'FC_h2Matrix_BH2D');
save(fullfile(MatricesCalculationDir, 'FC_h2Matrix_BH2U'), 'FC_h2Matrix_BH2U');
save(fullfile(MatricesCalculationDir, 'FC_h2Matrix_PH2D'), 'FC_h2Matrix_PH2D');
save(fullfile(MatricesCalculationDir, 'FC_h2Matrix_PH2U'), 'FC_h2Matrix_PH2U');
save(fullfile(MatricesCalculationDir, 'FC_MIMatrix_BMITD1'), 'FC_MIMatrix_BMITD1');
save(fullfile(MatricesCalculationDir, 'FC_MIMatrix_BMITD2'), 'FC_MIMatrix_BMITD2');
save(fullfile(MatricesCalculationDir, 'FC_MIMatrix_PMITD1'), 'FC_MIMatrix_PMITD1');
save(fullfile(MatricesCalculationDir, 'FC_MIMatrix_PMITD2'), 'FC_MIMatrix_PMITD2');
save(fullfile(MatricesCalculationDir, 'FC_MIMatrix_BMITU'), 'FC_MIMatrix_BMITU');
save(fullfile(MatricesCalculationDir, 'FC_MIMatrix_PMITU'), 'FC_MIMatrix_PMITU');
save(fullfile(MatricesCalculationDir, 'FC_TEMatrix_BTED'), 'FC_TEMatrix_BTED');
save(fullfile(MatricesCalculationDir, 'FC_TEMatrix_BTEU'), 'FC_TEMatrix_BTEU');
save(fullfile(MatricesCalculationDir, 'FC_TEMatrix_PTED'), 'FC_TEMatrix_PTED');
save(fullfile(MatricesCalculationDir, 'FC_TEMatrix_PTEU'), 'FC_TEMatrix_PTEU');
save(fullfile(MatricesCalculationDir, 'FC_CohMatrix_BCohF1'), 'FC_CohMatrix_BCohF1');
save(fullfile(MatricesCalculationDir, 'FC_CohMatrix_BCohW1'), 'FC_CohMatrix_BCohW1');
save(fullfile(MatricesCalculationDir, 'FC_CohMatrix_PCohF1'), 'FC_CohMatrix_PCohF1');
save(fullfile(MatricesCalculationDir, 'FC_CohMatrix_PCohW1'), 'FC_CohMatrix_PCohW1');
save(fullfile(MatricesCalculationDir, 'FC_CohMatrix_BCohF2'), 'FC_CohMatrix_BCohF2');
save(fullfile(MatricesCalculationDir, 'FC_CohMatrix_BCohW2'), 'FC_CohMatrix_BCohW2');
save(fullfile(MatricesCalculationDir, 'FC_CohMatrix_PCohF2'), 'FC_CohMatrix_PCohF2');
save(fullfile(MatricesCalculationDir, 'FC_CohMatrix_PCohW2'), 'FC_CohMatrix_PCohW2');
save(fullfile(MatricesCalculationDir, 'FC_GCMatrix_GC'), 'FC_GCMatrix_GC');
save(fullfile(MatricesCalculationDir, 'FC_GCMatrix_PGC'), 'FC_GCMatrix_PGC');
save(fullfile(MatricesCalculationDir, 'FC_GCMatrix_CondGC'), 'FC_GCMatrix_CondGC');Hugohttps://fr.mathworks.com/matlabcentral/profile/authors/17126897tag:fr.mathworks.com,2005:Question/7588892021-03-01T00:36:58Z2021-03-01T00:36:58ZExtract data from pdeplot to use contourfHello all,
I solved a pde and plotted the result with the code as follows. From the plotted figure, I would like to extract data to plot same or similar figure using contourf. Is there any way to do? Thank you very much in advance.
model = createpde();
R1 = [3,4,0,1,1,0,0,0,1,1]';
g = decsg(R1);
geometryFromEdges(model,g);
applyBoundaryCondition(model,'dirichlet','Edge',4,'u',100);
applyBoundaryCondition(model,'neumann','Edge',1,'g',10);
specifyCoefficients(model,'m',0,...
'd',0,...
'c',-1,...
'a',0,...
'f',1);
mesh = generateMesh(model,'Hmax',0.25);
results = solvepde(model);
figure
pdeplot(model,'XYData',results.NodalSolution)
Johnny Yoonhttps://fr.mathworks.com/matlabcentral/profile/authors/12150675tag:fr.mathworks.com,2005:Question/144062011-08-23T20:47:53Z2021-03-01T00:02:43ZLower bound on p-value returned by corrI'm using corr to calculate the p-value for the correlation between two datasets. It keeps returning a p-value of Zero.
Does anyone know the lower-bound on this calculation? I'm guessing its 1E-250 since that's the smallest I can generate with minor perturbations to the data.
In case it matters I'm using 2011A.Will Dampierhttps://fr.mathworks.com/matlabcentral/profile/authors/1084889tag:fr.mathworks.com,2005:Question/7566192021-02-26T05:53:28Z2021-03-01T00:00:37ZERROR SELECTING MULTIPLE FILESHI!
i have attached as much information as possible
so i have written a code to open a text file selected by user and to do whatever based on what the user chooses. this is the code that works.
[file, path] = uigetfile('.txt');
if isequal (file, 0)
disp ('user selected cancel')
else
disp(['user selected', fullfile(path,file)]);
end
COP = importdata(fullfile(path,file));
code works, no worries.
NOW the issue i am having is when the user wants to select and import multiple files. i have tried to do it using a for loop but it opens a structure and i dont know how to handle a struct. the loop i followed is similar to the one found in this link.. https://au.mathworks.com/matlabcentral/answers/71197-error-in-uigetfile-multiselect . so before anyone comes at me for not "trying" i have also tried stringcat and a lot of other methods, none of which worked.
its spits out this error
Error using importdata (line 139)
Unable to open file.
Error in 'trying' (line 13)
COP = importdata(fullfile(path,file));
COULD someone please provide some insight into why this is happening???? or what is wrong with my loop?
if you have nothing helpful to say please just don't say it. thanks.
sincerely a desperate student. diala yazbeckhttps://fr.mathworks.com/matlabcentral/profile/authors/7065882tag:fr.mathworks.com,2005:Question/7588792021-02-28T23:34:51Z2021-02-28T23:35:28Zuse 1D finite-difference methods to solve partial differential equations and non-uniform grids with direct and transformation methods.Hello I am confused on the matlab code for parts b-d I will attach my code below. The problem is in the PNG above.
%Part B
%set parameters for n=10
alpha = 1; %given
Lx = 15; %domain length
n = 10; %nodes
dx = Lx./n;
x = 0:dx:Lx; %distance between nodes
h = 0.1; %time step
Tmax =100; %max time
i = Tmax / h; %number of time steps
t = (0:h:Tmax); %time grid
T = zeros(i,n); %set matrix
for i = 1:i
T(1,:) = 0; % IC
T(:,1) = 0; % 1st
T(:,end) = 0.15; %last
S = (x.^2).*(exp(-x)); %given
for j = 2:1:n-1
T(i+1,j) = T(i,j) + ((alpha*h)./(dx^2)).*(T(i,j+1)-2*T(i,j)+T(i,j-1)) + h*S(j);
end
end
%Parameters for n = 20
alpha = 1; %given
Lx = 15; %domain length
n = 20; %new nodes
dx = Lx./n;
x = 0:dx:Lx; %distance between nodes
h = 0.1; %time step
Tmax =100; %max time
i = Tmax / h; %number of time steps
t = (0:h:Tmax); %time grid
T = zeros(i,n); %set matrix
for i = 1:i
T(1,:) = 0; % IC
T(:,1) = 0; % 1st
T(:,end) = 0.15; %last
S = (x.^2).*(exp(-x)); %given
for j = 2:1:n-1
T(i+1,j) = T(i,j) + ((alpha*h)./(dx^2)).*(T(i,j+1)-2*T(i,j)+T(i,j-1)) + h*S(j);
end
end
figure(1)
plot(T)
grid on;
title('Nx=10','fontsize',16)
figure(2)
plot(T)
grid on;
title('Nx=20','fontsize',16)
%Part C
alpha = 1; %given
Lx = 15; %domain length
n = 10; %nodes
dx = Lx./n;
x = Lx*(1-cos((pi*j)./(2*n))); %given
h = 0.1; %time step
Tmax =100; %max time
i = Tmax / h; %number of time steps
t = (0:h:Tmax); %time grid
T = zeros(i,n); %set matrix
for i = 1:i
T(1,:) = 0; % IC
T(:,1) = 0; % 1st
T(:,end) = 0.15; %last
S = (x.^2).*(exp(-x)); %given
for j = 2:1:n-1
T(i+1,j) = T(i,j) + ((alpha*h)./(dx^2)).*(T(i,j+1)-2*T(i,j)+T(i,j-1)) + h*S(j);
end
end
%Part D
alpha = 1; %given
Lx = 15; %domain length
n = 10; %nodes
x = Lx*(1-cos(s)); %new x
ds = Lx./n;
h = 0.1; %time step
Tmax =100; %max time
i = Tmax / h; %number of time steps
t = (0:h:Tmax); %time grid
T = zeros(i,n); %set matrix
s = acosd(1-(x./Lx)); %given
s1= 1./(sqrt(2*x*Lx-x.^2)); %first derivative of s
s2=(x-Lx)./((2*x*Lx-x.^2).^(3/2)); %second derivative of s
for i = 1:i
T(1,:) = 0; % IC
T(:,1) = 0; % 1st
T(:,end) = 0.15; %last
S = (x.^2).*(exp(-x)); %given
for j = 2:1:n-1
T(i,j) = T(i,j) + s2*((alpha*h)./(2*ds))*(T(i,j+1)-T(i,j-1))+(s1).^2*((alpha*h)./(ds^2))*(T(i,j+1)-2*T(i,j)+T(i,j-1))+h*s;
end
end
figure(1)
plot(T)Cassidy Holenehttps://fr.mathworks.com/matlabcentral/profile/authors/17512545tag:fr.mathworks.com,2005:Question/7574792021-02-26T21:51:09Z2021-02-28T23:27:41ZHow can I get randperm to return a permutation of a vector that has no entries at their original positions?I want take a random permutation of a vector such that all entries of the vector move to a new location.
For example, if I have a vector [1,2,3,4,5], then the following permutations are acceptable:
[2,1,4,5,3], [3,1,5,2,4], [5,4,2,3,1], etc.
However, for me, the following vector is not acceptable:
[2,4,3,5,1]
because the "3" has remained in the same location.
The "randperm" function in MATLAB allows for some of the entries in the vector to stay in the same position. Is there some way to use randperm that stops it from doing this? Or is there some other function out there that I am missing? (I have also looked at the functions "datasample" and "randsample" but they also do not seem to allow for this).Darcy Cordellhttps://fr.mathworks.com/matlabcentral/profile/authors/6864376tag:fr.mathworks.com,2005:Question/7588392021-02-28T22:21:32Z2021-02-28T23:21:04ZPlotting complicated function with asymptotesHi,
I am struggling to plot this equation in Matlab
I have tried using plot, fplot and ezplot but none seem to be able to handle it. Would anyone be able to help me with this?
Ben Phelpshttps://fr.mathworks.com/matlabcentral/profile/authors/20432249tag:fr.mathworks.com,2005:Question/7588742021-02-28T23:14:38Z2021-02-28T23:15:55ZArithmetic with repeated indicesI have an array of two-column rows which may or may not have repeated rows. I want to do some arithmetic operations, regardless of whether the rows are repeated. A simplified version of what I'm trying to do is given below:
arr = [1,2;3,4;1,2;5,6];
a = [1,100;2,200;3,300;4,400;5,500];
for i = 1:size(arr,1)
idx = find(ismember(a(:,1),arr(i,1)));
a(idx,2) = a(idx,2) + arr(i,2);
end
I would get
a =
1 104
2 200
3 304
4 400
5 506
I want to do something like
idx = find(ismember(a(:,1),arr(:,1)));
a(idx,2) = a(idx,2) + arr(:,2);
This works when there are no repeated entries, that is, idx has unique values. Can this be done when idx has repeated values as well?Tejashttps://fr.mathworks.com/matlabcentral/profile/authors/18205581tag:fr.mathworks.com,2005:Question/7588692021-02-28T23:09:29Z2021-02-28T23:09:29ZCNN code for detecting fireI need CNN Matlab code for detection fire in real-time applications.hanaahttps://fr.mathworks.com/matlabcentral/profile/authors/3549521tag:fr.mathworks.com,2005:Question/7588642021-02-28T22:59:34Z2021-02-28T23:03:01Zmexcuda in ubuntu errorTry to complie the Cuda file in ubuntu system but get error.
mexcuda GEMM_GPU.cu -lcublas
Building with 'nvcc'.
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu: In function ‘void mexFunction(int, mxArray**, int, const mxArray**)’:
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu:164:55: warning: narrowing conversion of ‘numCRows’ from ‘long long int’ to ‘mwSize {aka long unsigned int}’ inside { } [-Wnarrowing]
const mwSize dims[] = {numCRows,numCCols,batch_count};
^
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu:164:55: warning: narrowing conversion of ‘numCCols’ from ‘long long int’ to ‘mwSize {aka long unsigned int}’ inside { } [-Wnarrowing]
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu:164:55: warning: narrowing conversion of ‘batch_count’ from ‘int’ to ‘mwSize {aka long unsigned int}’ inside { } [-Wnarrowing]
Error using mex
/usr/bin/x86_64-linux-gnu-ld: cannot find -lcublas
collect2: error: ld returned 1 exit status
Error in mexcuda (line 166)
[varargout{1:nargout}] = mex(mexArguments{:});
As the cuda file uses cublas_v2 liburary, I add the path of the CUDA h files in the commend line but the error still exists:
mexcuda GEMM_GPU.cu -lcublas -I'/usr/local/cuda-9.0/include'
Building with 'nvcc'.
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu(164): warning: invalid narrowing conversion from "long long" to "unsigned long"
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu: In function ‘void mexFunction(int, mxArray**, int, const mxArray**)’:
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu:164:55: warning: narrowing conversion of ‘numCRows’ from ‘long long int’ to ‘mwSize {aka long unsigned int}’ inside { } [-Wnarrowing]
const mwSize dims[] = {numCRows,numCCols,batch_count};
^
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu:164:55: warning: narrowing conversion of ‘numCCols’ from ‘long long int’ to ‘mwSize {aka long unsigned int}’ inside { } [-Wnarrowing]
/home/ubuntu/New_folder/Local_version/GEMM_GPU.cu:164:55: warning: narrowing conversion of ‘batch_count’ from ‘int’ to ‘mwSize {aka long unsigned int}’ inside { } [-Wnarrowing]
Error using mex
/usr/bin/x86_64-linux-gnu-ld: cannot find -lcublas
collect2: error: ld returned 1 exit status
Error in mexcuda (line 166)
[varargout{1:nargout}] = mex(mexArguments{:});
Here are my device information after calling gpuDevice:
gpuDevice(1)
ans =
CUDADevice with properties:
Name: 'GeForce GTX 1080 Ti'
Index: 1
ComputeCapability: '6.1'
SupportsDouble: 1
DriverVersion: 10.2000
ToolkitVersion: 10.2000
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 1.1718e+10
AvailableMemory: 1.1399e+10
MultiprocessorCount: 28
ClockRateKHz: 1582000
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 0
CanMapHostMemory: 1
DeviceSupported: 1
DeviceSelected: 1
Here are the information after running gpu environment checker
puEnvObj = coder.gpuEnvConfig;
gpuEnvObj.GpuId = 1;
gpuEnvObj.BasicCodegen = 1;
gpuEnvObj.BasicCodeexec = 1;
results = coder.checkGpuInstall(gpuEnvObj)
Compatible GPU : PASSED
CUDA Environment : PASSED
Runtime : PASSED
cuFFT : PASSED
cuSOLVER : PASSED
cuBLAS : PASSED
Basic Code Generation : PASSED
Basic Code Execution : PASSED
results =
struct with fields:
gpu: 1
cuda: 1
cudnn: 0
tensorrt: 0
basiccodegen: 1
basiccodeexec: 1
deepcodegen: 0
deepcodeexec: 0
tensorrtdatatype: 0
profiling: 0
I try to find whether it is because of the problem of GCC, but it looks fine once I just try to use mexcuda to complie some CUDA files which don't need cublas lib:
mexcuda cuda_file_without_cublas_lib.cu
The cu file will be successfully completed without any warnning or errors.
Y.Yanghttps://fr.mathworks.com/matlabcentral/profile/authors/18124258tag:fr.mathworks.com,2005:Question/7586642021-02-28T17:14:28Z2021-02-28T23:02:14ZWhile loop in if and for loopHi all,
I am trying to combine a while loop in an if and for loop but I am having some problems with the results of my matlab code.
I am trying to recognize in a for and if loop wether a variable is true and as long as this variable is true I want it to execute a part of the code. As soon as this condition is not true, I want my code to go back to the for loop, with the new value of i. Here is an example of my code:
for i = 2:N
if Gyr_2(i,3) ~= 0 % Checks wether this condition is true for the value of i
[Output] = RBK2(Input); % Self created function
elseif Gyr_2(i,1) ~= 0 || Gyr_2(i,2) ~= 0 || Ori_2(i,1) ~= 0 || Ori_2(i,2) ~= 0 % Checks wether this condition is true for the value of i
[Output] = RBS2(Input); % Self created function
elseif Acc_2(i,3) ~= 0 % Checks wether this condition is true for the value of i
[Output] = RBH2(Input); % Self created function
else % If none of the conditions are true
[Output] = RBL2(Input); % Self created function
if Diagonal5(i) == 1 && Acc_3(i,1) ~= 0 && Acc_3(i,2) ~= 0 % Checks again if this condition is true
if abs(Vel_3(i-1,1)) > abs(Vel_3(i-1,2)) && Acc_2(i,2) ~= 0
while Diagonal5(i) == 1 %Value is either 1 or 0
[Output] = RBD2x(Input) % Self created function
i = i + 1;
end
else
while Diagonal5(i) == 1 && Acc_2(i,1) ~= 0
[Output] = RBD2y(Input) % Self created function
i = i + 1;
end
end
end
end
end
So basically, when it does the "while Diagonal5(i) == 1" I want the code to stay within this loop until Diagonal5(i) == 0. However it seems like it always jumps out of the while loop and goes back to the beginning of the for loop with the next value of i, instead of using the value of i when Diagonal5(i)==0. I have also done it without writing the "i = i+1;", but then when I start my code, it does not complete and takes a really long time to load.
Could you guys please tell me how i can fix that. I have read multiple different answers but have not found one that works for me. Should I otherwise write my code differently to solve this problem?
Thanks in advance
Sam :)Samuel Bofferdinghttps://fr.mathworks.com/matlabcentral/profile/authors/17955016tag:fr.mathworks.com,2005:Question/7587592021-02-28T18:43:36Z2021-02-28T22:59:52ZMatlab App connect and talk to an USB DeviceHello all,
I am programming an app to control a Spectano 100 via USB. I want to send different Values an plot some readings. I already have the GUI but I'm not getting anywhere with the programming. Here is a sample code from the manufacturer: https://documentation.omicron-lab.com/SpectanoAutomationInterface/1.60/articles/Add_AI_Reference.html
I don't know how to integrate it into my app. Do I need an extra m file?
Best regadsFabian Heynhttps://fr.mathworks.com/matlabcentral/profile/authors/13811151tag:fr.mathworks.com,2005:Question/7588592021-02-28T22:40:29Z2021-02-28T22:40:29ZHow to jump to the next reference value inside a for loop?So when line 0 condition is met, I want the for loop to jump 5 rows from the given data set of a single column. So when count1 ==5 , I want the loop to skip 5 rows from the column and take the 6th element as the new reference. [8,8,8,8,8,9,6,546,6,5,6,4,5,5,5,5,5]. In this dataset, the count value should be 2. Now what the issue is that the code given below does not skip to the 6th reference value to compare the next 5 values. I tried line 1 and 2 but those did not work or have any effect on the code.
count=0;
count1=0;
for i=1:length(data)-4
for j=i+1:i+4
if data(i)~=data(j)
count1=0;
break;
else
count1=count1+1;
end
if count1==5 % line 0
count=count+1;
%data(i,1)=data(i+5,1); //line 1
%data(i)=data(i+5); //line 2
else
continue;
end
end
end
Karthik Garimellahttps://fr.mathworks.com/matlabcentral/profile/authors/19624616tag:fr.mathworks.com,2005:Question/7579492021-02-27T16:01:02Z2021-02-28T22:37:02ZForcing Page Breaks in MATLABWhen working in the Live Editor, can I insert command lines that will force the output to start a new page when exporting to PDF?James Longhttps://fr.mathworks.com/matlabcentral/profile/authors/4881521tag:fr.mathworks.com,2005:Question/7588542021-02-28T22:34:55Z2021-02-28T22:35:45ZError: "Dimension argument must be a positive integer scalar within indexing range" using trapz
x_24= [0; 4.6958; 5.6732; 14.2002; 15.4490; 16.0151; 17.9994; 21.7987; 24.1082; 29.8818; 37.4162; 41.1113; 55.6853; 59.9431]
z_24=[ 6.1876; 7.1381; 7.2346; 4.4075; 4.4321; 4.2854; 3.9659; 3.4729; 3.1695; 2.2887; 1.2414; 0.8183; -0.0147; -0.2389]
NM_18=0.82;
MHWS_18=1.5-NM_18;
z_MHWS_24=z_24-MHWS_18;
MHWS_vector_18=repmat(MHWS_18,79,1);
figure(1)
plot (x_24,z_MHWS_24,'Yellow')
hold on
plot(MHWS_vector_18,'Blue')
hold off
x=x_24;
z=z_MHWS_24;
xi=5.67;
xf=14.20;
xRange = [xi,xf];
% find logical indices for range of interest
idl = x >= xRange(1) & x <= xRange(2);
% provide just values of interest to trapz
area_selected=trapz(x(idl),z(idl))
area_total=trapz(x,z)
The error that is happening is in the last two lines of the code above (from bottom to top).Jacqueline Rigattohttps://fr.mathworks.com/matlabcentral/profile/authors/19811265tag:fr.mathworks.com,2005:Question/7588042021-02-28T20:14:35Z2021-02-28T22:30:08Zusing a function with matricesHi! I am attempting to write a function that wil have three inputs that are all equally sized vectors, and use if statements to produce one vector as an output. I have my if stetments as a function file and my vectors prepared, but running the function with the vectors as inputs gives the error message that the output was not assigned during the call to my function. the function would look something like:
[rating] = rating(x,y)
if x <4
rating=1;
elseif x<10 && y<3
rating=2;
else
rating=3;
where x and y are vectors, and rating will be a vector of the same size as x and y where the values are determined using the x adnd y vectors. like rating([1 2],[6 2]) would give [1 2]David Dunganhttps://fr.mathworks.com/matlabcentral/profile/authors/21026246tag:fr.mathworks.com,2005:Question/7588492021-02-28T22:27:39Z2021-02-28T22:27:39ZTimeseries plots only first column after applying condition + how to select individual columnsI have a timeseries already, but this effect happens even when I create ones myself. Say:
ts1 = timeseries(rand(20,5)); %this is one I created myself
Plotting ts1 by plot(ts1) or plot(ts1.Data) yields five lines as is expected.
Let's say I want to plot only the values of ts1 which have a time greater than 1 second. I do:
plot(ts1.Data(ts1.Time > 2))
This only yields one line corresponding to the column (Data:1), but with the correct condition applied. Why is this and how can I have all five lines plotted with the conditions in place?
Also, how do I select individual columns such as Data:3 for example?Amritz Ansarahttps://fr.mathworks.com/matlabcentral/profile/authors/14853089tag:fr.mathworks.com,2005:Question/7588242021-02-28T21:08:39Z2021-02-28T22:26:45Zhow to write a bisection loop?y = (-0.50598*10^-10)*x.^3 + (0.38292*10^-7)*x.^2 + (0.74363*10^-4)*x + 0.88318*10^-2
and I am trying to use bisection to find three point for this function, here is what I did.
For bisection one: xl = -1000 and xu = -500, xm = (-1000+(-500))/2 = -750
If xl*xu < 0
Xu=xm
Xm=(xl+xu)/2
error = ((xm-xu)/xm)*100
end
If xl*xu >0
xl = xm
Xm=(xl+xu)/2
error = ((xm-xu)/xm)*100
end
If error < 5
end
this is what I plan to do in word I dont know how to make a funtion to start it. wenchong chenhttps://fr.mathworks.com/matlabcentral/profile/authors/18123326tag:fr.mathworks.com,2005:Question/7584192021-02-28T08:35:38Z2021-02-28T22:23:28ZHow to use Xlswrite command in actxserver and how to avoid script gets hanged due to hworkbook.close command?Hi
I have two queries in the below codes.
Query 1: How to involve the xlswrite command in actxserver.
FYI: Names{gp} --> Heading name to be placed in excel sheet from A1.
data_peak{gp} --> data to be placed in excel sheet from A2.
gp --> used to work in for loop.
Somehow i made with xlswrite through conventional method and autofit the columns thorugh actxserver. But the time will be saved if xlswrite command also to be invloved in the actxserver itself.
Query 2: When i used to close the workbook using hWorkbook.Close command, the script gets hanged and it doesn't go to the next line. I dont know th reason why it is hanged and it doesnot show any warning or error.
xlswrite(fullFileName,T,Names{gp},'A1'); % Title on the first row of excel sheet
xlswrite(fullFileName,data_peak{gp},Names{gp},'A2'); % Data on the second row of excel sheet
%% Excel application - actxserver
hExcel = actxserver('Excel.Application');
hWorkbook = hExcel.Workbooks.Open(fullFileName);
% Select the entire spreadsheet.
hExcel.Cells.Select;
% Auto fit all the columns.
hExcel.Cells.EntireColumn.AutoFit;
% Center align the cell contents.
hExcel.Selection.HorizontalAlignment = 3;
hExcel.Selection.VerticalAlignment = 2;
% Put "cursor" or active cell at A1, the upper left cell.
hExcel.Range('A1').Select;
hWorkbook.Save
% delete the sheets
try
sheetName = 'Sheet';
hExcel.ActiveWorkbook.Worksheets.Item([sheetName '1']).Delete;
catch ME
end
hWorkbook.Close
hExcel.Quit
hExcel.delete
clear hExcel
Kindly provide me some ideas to get rid of these two issues and let me know if you need any further information.
Thanks in advance.Gopinath Karuppannanhttps://fr.mathworks.com/matlabcentral/profile/authors/16682058tag:fr.mathworks.com,2005:Question/7588442021-02-28T22:23:23Z2021-02-28T22:23:23Zstacked (rows) of tabs in AppDesigner?The input area of my app has a bunch of tabs, and User can't see all of them at the same time. I would like to add rows to the name tabs, so I can show more at the same time.
What I have:
What I would like to have:
Any advice?Cathie Kesslerhttps://fr.mathworks.com/matlabcentral/profile/authors/3803244tag:fr.mathworks.com,2005:Question/7584792021-02-28T11:01:37Z2021-02-28T22:16:37ZHow to extend the colon operator for my own classI am about to write an arithmetics for matlab.
Now I try to include the colon operator, i.e. to define the function colon for my class of numbers.
What do I have to do to implement the colon function? I know that the return type is a so called range
and for me as a java programmer it looks very much like an iterator,
i.e. an object allowing the functions hasnext(.) and next(.).
Please give me a hint on how to do it. Ernst Reissnerhttps://fr.mathworks.com/matlabcentral/profile/authors/6229746tag:fr.mathworks.com,2005:Question/7586542021-02-28T16:52:15Z2021-02-28T22:15:26ZHow do I calculate this definite integral in matlabhello. I want to calculate this integral. But it does not answer.
please check it. thanks
clc
clear
syms x
f = (124-x)^3/((12.152-2*x)^2*(1.24-x));
F = int(f, x, 0, 4.23)
Behzad Rahmanihttps://fr.mathworks.com/matlabcentral/profile/authors/21632399tag:fr.mathworks.com,2005:Question/7586242021-02-28T16:12:56Z2021-02-28T22:09:26Zuse vector as inputI want to give each input of a vector as an argument to my function to recive a list of values that i can then plot (my goal is to plot the time it takes to execute the function for a given n). The problem is, that i only get the output of the first entry of the vector. What did I do wrong?
>> n = [1:1:10];
>> [a,b] = calcEulerSum2 (n)
it returns only calcEulerSum2(1)
function [e, a] = calcEulerSum2(n)
den = 1;
e = 1;
tic
for i = 1 : n
den = den * i;
e = e + 1/den;
end
a = toc;
endVincent Degondahttps://fr.mathworks.com/matlabcentral/profile/authors/21619759tag:fr.mathworks.com,2005:Question/7584542021-02-28T10:15:12Z2021-02-28T21:54:59ZA question about MATLAB library "vibration of rotary machinery"My question is about vibration of rotary machinery:
https://au.mathworks.com/help/signal/ug/vibration-analysis-of-rotating-machinery.html
The author claims the wavforms correponding to input shaft, output shaft, and gear mesh measured by sensors can be reported as:
vfIn = 0.4*sin(2*pi*fPin*t); % Pinion waveform
vfOut = 0.2*sin(2*pi*fGear*t); % Gear waveform
vMesh = sin(2*pi*fMesh*t); % Gear-mesh waveform
A1 sensor can measure vfOut.
A2 sensor can measure vMesh.
But how can you measure vfIn?
Si Sohttps://fr.mathworks.com/matlabcentral/profile/authors/20792574tag:fr.mathworks.com,2005:Question/7587642021-02-28T18:44:14Z2021-02-28T21:53:33ZHow can I read text files and compile a joint XY Position historyHello eveyone,
I am struggling with finding a solution to my problem. I have numerous a json text files with XY position co-ordinates obtained from a 2D human pose estimation. I would like to read and use particular data keypoints from the XY coordinates for each JSON file in order to plot joint angle history for example. Is there a way to convert the data into an array? I have been struggling with numerous Matlab functions (fgets, fscanf) albeit with no luck and I am a bit lost.
The below data is what is contained on the numerous JSON files I have (a json file for each frame captured during the pose estimation video). The XY data below indicates the XY coordinate for each pose keypoint with a confidence reading/percentage for how accurate the pose estimation software believes that XY coordinate is. For example for the first keypoint for the Nose, the XY coordinate (with its confidence reading) is 314.19, 94.238, 0.934092 (both pieces of info are in BOLD in the data below.
{"version":1.3,"people":[{"person_id":[-1],"pose_keypoints_2d":[314.19,94.238,0.934092,305.601,109.546,0.891856,288.369,111.457,0.862389,268.27,130.557,0.860192,280.744,125.806,0.860478,322.797,106.684,0.84053,353.393,92.3152,0.859181,375.415,77.0249,0.859859,310.392,186.998,0.760913,296.043,186.045,0.705134,277.88,246.273,0.866712,234.798,229.088,0.834373,325.659,187.963,0.724311,354.392,233.851,0.880398,343.864,294.145,0.808459,309.387,88.5102,0.968337,317.993,89.4436,0.927254,295.042,87.5593,0.901007,0,0,0,364.873,300.81,0.505551,362.036,297.926,0.442485,338.115,300.781,0.724548,213.795,238.663,0.719225,212.839,233.886,0.699098,232.92,223.355,0.603927],"face_keypoints_2d":[],"hand_left_keypoints_2d":[],"hand_right_keypoints_2d":[],"pose_keypoints_3d":[],"face_keypoints_3d":[],"hand_left_keypoints_3d":[],"hand_right_keypoints_3d":[]}]}
{"version":1.3,"people":[{"person_id":[-1],"pose_keypoints_2d":[314.19,94.238,0.934092,305.601,109.546,0.891856,288.369,111.457,0.862389,268.27,130.557,0.860192,280.744,125.806,0.860478,322.797,106.684,0.84053,353.393,92.3152,0.859181,375.415,77.0249,0.859859,310.392,186.998,0.760913,296.043,186.045,0.705134,277.88,246.273,0.866712,234.798,229.088,0.834373,325.659,187.963,0.724311,354.392,233.851,0.880398,343.864,294.145,0.808459,309.387,88.5102,0.968337,317.993,89.4436,0.927254,295.042,87.5593,0.901007,0,0,0,364.873,300.81,0.505551,362.036,297.926,0.442485,338.115,300.781,0.724548,213.795,238.663,0.719225,212.839,233.886,0.699098,232.92,223.355,0.603927],"face_keypoints_2d":[],"hand_left_keypoints_2d":[],"hand_right_keypoints_2d":[],"pose_keypoints_3d":[],"face_keypoints_3d":[],"hand_left_keypoints_3d":[],"hand_right_keypoints_3d":[]}]}
[dpb edit -- added copy as code so the select button will work to get the text if folks want to try their hand at it...]
description of each XY coordinate: (not in json file)
# {0, "Nose"},
# {1, "Neck"},
# {2, "RShoulder"},
# {3, "RElbow"},
# {4, "RWrist"},
# {5, "LShoulder"},
# {6, "LElbow"},
# {7, "LWrist"},
# {8, "MidHip"},
# {9, "RHip"},
# {10, "RKnee"},
# {11, "RAnkle"},
# {12, "LHip"},
# {13, "LKnee"},
# {14, "LAnkle"},
# {15, "REye"},
# {16, "LEye"},
# {17, "REar"},
# {18, "LEar"},
# {19, "LBigToe"},
# {20, "LSmallToe"},
# {21, "LHeel"},
# {22, "RBigToe"},
# {23, "RSmallToe"},
# {24, "RHeel"},
# {25, "Background"}Ross Normanhttps://fr.mathworks.com/matlabcentral/profile/authors/20472567tag:fr.mathworks.com,2005:Question/7587892021-02-28T19:29:33Z2021-02-28T21:41:16Zclosed form solution in a system of equationDear friends, Hi
I am trying to find closed form solution for a system of equations (8 equations and 8 variables). All the equations are both non-linear and parametric.
I used "solve" in coding but I faced this massage: no explicit solution.
How could I improve my codes for having the parametric solution? Is there any other function?Mahsa Babaeehttps://fr.mathworks.com/matlabcentral/profile/authors/16640648tag:fr.mathworks.com,2005:Question/7568142021-02-26T09:05:44Z2021-02-28T21:40:38ZSolve non-linear equations system parametrically, Why are the answers empty?clear all;
clc;
syms X1 X2 X3 X4 X5 X6 X7 X8 X9 h k1 Lz1 k21 Lz2 k32 Lz3 a1 a2 a3 b1 b2 b3 w1 w2 w3 r1 r2 r3;
e0 = X1-1 == 0;
e1 = h*X1-k1*X7*X4==0;
e2 = X1*cos(X7*Lz1)+X4*sin(X7*Lz1)-X2==0;
e3 = -X1*X6*sin(X7*Lz1)+X4*X6*cos(X7*Lz1)-X8*X5*k21==0;
e4 = X2*cos(X8*Lz2)+X5*sin(X8*Lz2)-X3==0;
e5 = -X2*X8*sin(X8*Lz2)+X5*X8*cos(X8*Lz2)-X9*X6*k32==0;
e6 = X3*cos(X9*Lz3)+X6*sin(X9*Lz3)==0;
e7 = (a1/a2)*(b1^2+r1^2+X7^2+w1^2)-b2^2-r2^2-w2^2-X8^2 ==0;
e8 = (a1/a3)*(b1^2+r1^2+X7^2+w1^2)-b3^2-r3^2-w3^2-X9^2 ==0;
sol = solve([e0,e1,e2,e3,e4,e5,e6,e7,e8],[X1 X2 X3 X4 X5 X6 X7 X8 X9]);
Why are the answers empty?
X1: [0×1 sym]
X2: [0×1 sym]
X3: [0×1 sym]
X4: [0×1 sym]
X5: [0×1 sym]
X6: [0×1 sym]
X7: [0×1 sym]
X8: [0×1 sym]
X9: [0×1 sym]Arash Pourkazemihttps://fr.mathworks.com/matlabcentral/profile/authors/19550592tag:fr.mathworks.com,2005:Question/7586792021-02-28T17:23:55Z2021-02-28T21:37:06ZFast Restart in Response Optimization ToolI'm trying to use the Fast Restart option in the Response Optimization tool with my Simscape model, (I'm doing a "signal tracking" scenario). Specifically I'm using a thermal nodal model in Simscape (thermal resistors, capacitors, temperature sources, convective loads, and heat sources). I define these parameters in a separate Matlab .m file and run it prior to running the Simscape model. The response optimization will run when I do not use fast restart, but it takes an incredibly long time because it is compiling the model each and every iteration. When I try to use the fast restart mode, it says "these parameters (parameter names) cannot be modified while the model is in FastRestart. Either do not modify these parameters or run the model in normal mode". Is this a limitation of the program or could I be doing something wrong. I'm trying to tune values of thermal resistances, capacitances, and heat values.Adam Whelanhttps://fr.mathworks.com/matlabcentral/profile/authors/21671029tag:fr.mathworks.com,2005:Question/7588342021-02-28T21:33:59Z2021-02-28T21:33:59ZRename IO for blocks in SimulinkHello,
I want to rename the IO of a black in simulink, is this something that can be done?
If so how can it be done?
Thanks.Connor Wrighthttps://fr.mathworks.com/matlabcentral/profile/authors/17355742tag:fr.mathworks.com,2005:Question/988862009-06-27T01:12:00Z2021-02-28T21:33:53ZHow do I install MATLAB or other MathWorks Products?I would like to install a standalone MATLAB and/or other MathWorks product license on my internet-connected computer. How can I do this?MathWorks Support Teamhttps://fr.mathworks.com/matlabcentral/profile/authors/4622813