https://www.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2019-06-27T02:00:07Ztag:www.mathworks.com,2005:Question/4690972019-06-27T02:00:07Z2019-06-27T02:00:07ZHow to get the max level and the fields name of the HDF5 data?About one hdf5 data info, how can i get the max level and the fields name of the HDF5 data?
Please help me with detail steps, thanksapplehttps://www.mathworks.com/matlabcentral/profile/authors/2431179-appletag:www.mathworks.com,2005:Question/4689032019-06-26T02:43:09Z2019-06-27T02:00:07ZFilling Area with gray color scale.I am working on a figure and a came up with a surface area which is cone shape(plotted by two variables X and Y), and has five layers. I want to fill the area of each layer based on the intensity of gray color represented by matrix Z. The figures changes therefore i cannot save it first and modify it rather I want to modify it on the plot as facecolor. When I use imshow(I, []);, the two figures are plotted differently.
How can I fill the area (Area) with various layers of imshow(I, []) colors? Be free to use ant example or linspace to generate X, Y and Z values.
X=[j,i]; % currently j=5,the maximum value of L i=301 ,but this can change based on the variable.
Y=[j,i]; % Y is not directly related to X, but the size varies.
Z=[j,i-1]; % Z varies from 0 to max of 100 and is set to represent a measure of the intensity of the gray color
I = mat2gray(Z,[0 max(max(Z))]);
imshow(I, []);
Color=['I' 'r' 'c' 'm' 'k'];
figure(14)
hold on
for j=L:-1:1 % is set currently at 5.
Area(j,:)=area(X(j,:),Y(j,:),'FaceColor',Color(j)); %Area layers.
endDAVID OYUGIhttps://www.mathworks.com/matlabcentral/profile/authors/12629193-david-oyugitag:www.mathworks.com,2005:Question/4689402019-06-26T08:30:02Z2019-06-27T01:49:25ZUse of nargin and varargin Hey all,
Hope everyone is doing good. I need some help in fixing out my problem. I have a function which is shown below. Sometimes user give more inputs or less inputs But here there are four combinations of giving the input like below.
Area horizontal + Diameter inside (sometimes like this also possinle: Area horizontal + diameter inside + diameter outside)
Area horizonatl + diameter outside
Area vertical + diameter insie (sometimes like this also possinle: Area Vertical + diameter inside + diameter outside)
Area vertical + diameter inside
This is my function;
function [ L_ges ] = LL_Leitwert_freie_Konvektion_Strahlung( A_Horizontal ,A_Vertical,d_outside,d_Inside)
% Detailed explanation goes here
d_outside = d_outside/1000; % Umrechnung in m
d_inside = d_Inside/1000; % Umrechnung in m
A_Horizontal = A_Horizontal/1000/1000; % Umrechnung in m^2 Horizontal area
A_Vertical = A_Vertical/1000/1000; % Umrechnung in m^2
d_WK_M = d_Innen+b_Bauteil/2;
end
Still function has further calculations, I think it is not needed now.
Here what I needed is, When the user enter first combination input arguments, diameter outside(shouldn't be zero sometimes) and area vertical should be zero. Similary for vertical outside and vertical inside,
i think it is possible using nargin or varargin like below, But I am not getting how to do it.
It is like making some arguments zero according to the user input. Here also I am not sure, whether it is possible or not!.
if there another way of sloving it, that is also most welcomed.
Any suggestions and answers are most welcomed
Thanks in advancesurendra kumar Aralapura mariyappahttps://www.mathworks.com/matlabcentral/profile/authors/12717067-surendra-kumar-aralapura-mariyappatag:www.mathworks.com,2005:Question/4690742019-06-26T21:07:28Z2019-06-27T01:47:16ZHow do I perform a frequency sweep on a .WAV file?Hello,
I found the following code online and am using it as a sort of template for performing a frequency sweep on a .WAV file in MatLab.
wave_file = 'name.wav';
[wave_data_time, sample_rate] = wavread('name.wav');
N_temp = length(wave_data);
N = 2^nextpow2(N_temp);
buff = floor((N-N_temp)/2)+1;
Nyq = sample_rate/2;
df = sample_rate/N;
f = -Nyq:df:Nyq-df;
wave_data_time_pad = zeros(size(f));
wave_data_time_pad(buff:buff-1+N_temp) = wave_data_time;
wave_data_freq = fftshift(fft(wave_data_time_pad));
figure;
plot(f,real(wave_data_freq),'b-',f,imag(wave_data_freq),'r-');
However, after compiling, I am recieving this error:
Undefined function or variable 'wavread'.
Error in freq_sweep_ECE223 (line 2)
[wave_data_time, sample_rate] = wavread('name.wav');
Is there an alternative function or approach that newer versions of MatLab supports? Also, is there an easier way to perform a frequency sweep on an input audio file using the spectrogram function in MatLab?
Many thanks!regan garnerhttps://www.mathworks.com/matlabcentral/profile/authors/15228364-regan-garnertag:www.mathworks.com,2005:Question/4690952019-06-27T01:36:13Z2019-06-27T01:46:17Zsum of multiplication for a vector and matrix Say I have the following matrix and vector:
A = [ 2,3; 1,4] b= [ 5 , 7 ]
I want a code of the sum of the multiplication, such that each element of the matrix's first row are multiplied by the 1st cell of the vector, and the elements of the matrix's second row are multiplied by the 2nd cell of the vector, as follows:
2*5+3*5+1*7+4*7
( I will need this for a 1000*1000 matrix and a 1*1000 vector, but i used this example to clarify )
Abbi Hashemhttps://www.mathworks.com/matlabcentral/profile/authors/14329853-abbi-hashemtag:www.mathworks.com,2005:Question/4690962019-06-27T01:36:40Z2019-06-27T01:36:40ZVoronoi Diagram Boundaries with a given width I had a problem with Voronoi function now. I wish that I can remain a width, say, x(a variable) for each grid.Here is my code but that's wrong. Attached please find a pic that exactly shows what I want to do with Voronoi Diagram.
A = [3,7,2,8,5];
B = [6,1,0,8,1];
x=2;
Voronoi(A,B,"LineWidth",x);
There is a pic telling what I need.Boxun YANhttps://www.mathworks.com/matlabcentral/profile/authors/14902345-boxun-yantag:www.mathworks.com,2005:Question/4690942019-06-27T01:34:39Z2019-06-27T01:34:39ZIt is possible to export a live script to an interactive webpage?Like the examples in the following link:
https://www.mathworks.com/products/matlab/live-script-gallery.htmlTadashihttps://www.mathworks.com/matlabcentral/profile/authors/3293669-tadashitag:www.mathworks.com,2005:Question/4678452019-06-19T07:56:24Z2019-06-27T01:26:03ZSimulation of Clutter Affected by Transmitting WeightI want to give the transmitter array taylor weight to reduce sidelobes。
when i use the phased.ConstantGammaClutter ,i found the echo‘s energy is different by different element on array。
i don not want to weight my receive array , the echo‘s energy received by the array on the collector should be same.
i need help
(中文版)
我在使用相控阵工具箱仿真杂波时遇到了一个问题。
我仿真的情况是，在发射时，对阵元加一个低旁瓣的权，接收杂波的时候先不做处理。
但是，matlab提供的杂波仿真工具，只有一个关于阵列的输入选项。
我的发射阵列和接受阵列是同一个阵列，但是发射的时候会加权，接收的时候不做加权，应该怎么操作？
（如果在杂波仿真工具phased.ConstantGammaClutter 中的 ula 参数选择泰勒加权的阵列，则接收到的回波信号的幅值 不同阵元是不同的 这显然是不对的 ）
（机载地杂波仿真问题）
（question about airborne radar and clutter）Xin Donghttps://www.mathworks.com/matlabcentral/profile/authors/13126055-xin-dongtag:www.mathworks.com,2005:Question/4690502019-06-26T18:49:46Z2019-06-27T01:23:24ZHow can I read a specific range of lines from a text file without using a for loop?I need to read data from text files (a lot of them), and they are formatted as follow:
.
.
.
internalField nonuniform List<scalar>
241920
(
0
0
0
0
0
.
.
.
0
0
0
)
;
.
.
.
The data I'm interested is the zero after the "(". The 241920 is the number of lines of data. The numbers are not necesarily 0 (if it matters, their values are constrained as ).
I want to get these numbers in an array. So far, I first read the line containing the number of data points (it is located in line 22 of the text file) to intialize the array, then I used textscan in a for loop to read the text file line by line starting from line 24. The problem is that this process is VERY slow, and I need to read hundreds of these files (the number of rows can vary, but is always specified in line 22)
Here is the for loop I'm using (I copied the textscan funtion from another post, I'm honestly not sure how it works)
for i=1:fieldSize
alpha(i) = str2double(string(textscan(fileID,'%s',1,'delimiter','\n', 'headerlines',(linenum+i-1)-1)));
fseek(fileID, 0, 'bof');
end
% Where fieldSize is the number found on line 22 as previously mentioned
% linenum is where the data starts (which is 24 for these text files). The -2 added to the linenum is just to match the code I got it from
% alpha is the array to where the data is being exported to
What I want to do then is to make this code very efficient, and to do that I believe I need to eliminate the for loop and use a function that can read a range of lines, not necesarily starting at the beginning of the text file.
EDIT:
I attached a sample text file. The first 22 lines are constant, just info file from the program that produced the text file.Dennis Bonillahttps://www.mathworks.com/matlabcentral/profile/authors/15725099-dennis-bonillatag:www.mathworks.com,2005:Question/4690902019-06-26T23:49:32Z2019-06-27T01:18:24ZString matrix compare to get common in rowsDeal all, i have a problem to compare two string matrix :
A1 = {'AA', 'b' ; 'cc', 'ff'}
A2 = {'ee', 'AA' ; 'hhh', 'm'}
strcmp(A1,A2)
I get
A1 =
'AA' 'b'
'cc' 'ff'
A2 =
'ee' 'AA'
'hhh' 'm'
ans =
0 0
0 0
But i need to get
'AA' is common between A1 iand A2 in the row 1
Best regardTouts Toutshttps://www.mathworks.com/matlabcentral/profile/authors/12520337-touts-toutstag:www.mathworks.com,2005:Question/4690892019-06-26T23:38:43Z2019-06-27T01:14:37ZI need some help in seeing where I am going wrong and how to proceed with writing a particular funciton for a MATLAB course I am taking please.The question is this:
Write a function called max_sum that takes v, a row vector of numbers, and n, a positive integer as inputs. The function needs to find the n consecutive elements of v whose sum is the largest possible. In other words, if v is [1 2 3 4 5 4 3 2 1] and n is 3, it will find 4 5 and 4 because their sum of 13 is the largest of any 3 consecutive elements of v. If multiple such sequences exist in v, max_sum returns the first one. The function returns summa, the sum as the first output argument and index, the index of the first element of the n consecutive ones as the second output. If the input n is larger than the number of elements of v, the function returns 0 as the sum and -1 as the index. Here are a few example runs:
[summa, index] = max_sum([1 2 3 4 5 4 3 2 1],3)
summa = 13
index = 4
[summa, index] = max_sum([1 2 3 4 5 4 3 2 1],2)
summa = 9
index = 4
THe code I have written so far is as follows. My problem is that I am stuck on obtaining the largest possible sum. I wrote code and have been able to generate different sums in a vector but I am unable to put those answers in a vector themselves, by putting the answers in a vector I want to be able to use the 'max' function to obtain the largest sum. I haven't even touched finding the 'index' portion yet. Here's my code:
function [summa,index] = max_sum(v,n)
r = 0;
summa = zeros(1,length(v)); %% created a vector of 0's to length of v
if n > length(v)
summa = 0;
index = -1;
else
while n <= length(v)
summa = sum(v(r+1:n)) % here need to replace 0's with the sum (with logical index) so i can choose max
r = r+1;
n = n+1;
end
summa = max(summa);
index = n;
end
%summa = v;
%index = n;
end
Again, I need some help because I am unsure how to proceed from here. Thank you.
Alexander Villanuevahttps://www.mathworks.com/matlabcentral/profile/authors/15395632-alexander-villanuevatag:www.mathworks.com,2005:Question/4689492019-06-26T09:10:05Z2019-06-27T00:54:51Zfind mask model in SimulinkHi,
I have a problem that I want to find the Mask block inside of the existing model. I try to use find_system('System','BlockType','name_of_mask') to get the name of masked blocks. However,it return empty cell for me. What command should I use to find the masked blocks ?
Thanks!shengchang gaohttps://www.mathworks.com/matlabcentral/profile/authors/13466268-shengchang-gaotag:www.mathworks.com,2005:Question/4690852019-06-26T23:10:01Z2019-06-27T00:52:23ZUsing Matlab to automate excel calculationsI have a legacy excel sheet that I need to run a large number of calulations through. The spreadsheet has a number of input cells (I only need to vary two keeping the other constant) And a output section, when the excel sheet is open, changing a value in the input section causes the excel sheet to immediately update with the new values. I need to run through a couple hundred sets of input values and would rather not copy and paste results all day. Is there a clever way to get Matlab to open the excel calulator, change the input values according to an array, read the output cells and store them in Matlab? My concern is that when using the normal excel import functions the output values will not change with the varying inpout values while accessing the sheet from another program.
VBA must be able to do this but I am much more familiar with Matlab and am on a bit of a time crunch so learning VBA will have to wait to another day. Thanks! Dominic Gallegoshttps://www.mathworks.com/matlabcentral/profile/authors/15615127-dominic-gallegostag:www.mathworks.com,2005:Question/4690932019-06-27T00:26:14Z2019-06-27T00:51:55ZI need to Integrate Winzip into a Matlab ETL program that incorperates uigetfile and uiputfile. Does anyone have experience with this before?I need to integrate winzip into a matlab ETL program that incorperates uigetfile and uiputfile. Does anyone have experience with this before? The zip/unzip function is way too slow on large airline blackbox files....
.zip -> gz -> lts -> .csv !goal!Jered Willoughbyhttps://www.mathworks.com/matlabcentral/profile/authors/15545726-jered-willoughbytag:www.mathworks.com,2005:Question/4680702019-06-20T13:09:08Z2019-06-27T00:51:26Zwhy does sine curve not properly plotted in simulinkShivank Anchalhttps://www.mathworks.com/matlabcentral/profile/authors/15630962-shivank-anchaltag:www.mathworks.com,2005:Question/4690912019-06-27T00:06:41Z2019-06-27T00:24:51ZError using nlinfit for logarithmic modelHello,
I'm trying to fit a logarithmic model to my data but I keep geting the following error:
Error using nlinfit>checkFunVals (line 641)
The function you provided as the MODELFUN input has returned Inf or NaN values.
clear all, clc;
y=[0;0.1244; 0.1569; 0.1016; 0.2784; 0.4066; 0.2746; 0.7044; 0.7061;...
0.7054; 0.6752; 0.7102; 0.707];
x=[0; 1; 11; 13; 19; 25; 31; 38; 55; 61; 74; 92; 109];
fun = @(a,x)a(1)*log(x);
a0=0.15;
f = nlinfit(x,y,fun,a0);Oriol Sanchez Rovirahttps://www.mathworks.com/matlabcentral/profile/authors/8023189-oriol-sanchez-roviratag:www.mathworks.com,2005:Question/4690312019-06-26T16:57:46Z2019-06-27T00:20:06Z3D Surface or Multiple Line Plots from 16 iterations of 3 column XYZ DataAttempting to create a 3D line plot XYZ being Dark Counts/s, Pixel No., and no. of SPADS activated. Bascially I have Dark count data for 512 pixels XY line plots, however I have repeated for different number of SPAD sensors activated per pixel ranging from 1 turned on to 16 SPADs on, I was trying to find a way to create a 3D multiple line plot, or a surface plot of some kind, appreciate any help!
The attached document I've created is in XYZ format and for Z column is 1-16 depending on the data, hopefully this makes some sense to someone!
15SPAD3D contains an excerpt of the 3DDCRXYZ file for handiness.Eunan McShanehttps://www.mathworks.com/matlabcentral/profile/authors/13871616-eunan-mcshanetag:www.mathworks.com,2005:Question/4690842019-06-26T22:47:09Z2019-06-27T00:08:47ZHow to cluster heat maps?Hi,
I have some contour heatmaps with 5 or 6 categorized pressure points for different channels (y-axis). The yellow shade means high pressure and blue is lower end. I was wondering if there is already an algorithm which clusters the heat maps into groups. For instance the one I am pasting here has some patches of yellow and I have some more similar graphs. Now I want that my algorithm should categorize them according to some cluster it defines intuitively or explicitly. So it gives me a "n" number of different clusters for lets say 100 plots and then I can work on it or optimize it if possible. Please help. Thank you so much.Abhishek Singhhttps://www.mathworks.com/matlabcentral/profile/authors/13914225-abhishek-singhtag:www.mathworks.com,2005:Question/4690922019-06-27T00:08:16Z2019-06-27T00:08:16ZWhy does gctest fail when using discontinuous lags?I'm running a Granger-causality test on a varm model object. The gctest function returns an indexing error when the lags are discontinuous. For example it works when lags = 1,2,3,4. It fails when lags = 1,2,4. Below code recreates the error.
%Following Matlab gctest example
load Data_USEconModel
m1slrate = price2ret(DataTable.M1SL);
inflation = price2ret(DataTable.CPIAUCSL);
rgdprate = price2ret(DataTable.GDP./DataTable.GDPDEF);
tbl = table(m1slrate,inflation,rgdprate);
tbl = rmmissing(tbl);
T = size(tbl,1); % Total sample size
numseries = 3;
% Partition time base.
maxp = 4; % Maximum number of required presample responses
idxpre = 1:maxp;
idxest = (maxp + 1):T;
% Fit VAR models to data.
Y0 = tbl{idxpre,:}; % Presample
Y = tbl{idxest,:}; % Estimation sample
%Two different models. Second model omits lag number 3
lags1=[1:4];
lags2=[1,2,4];
coef0=nan(numseries,numseries);
numlags1=length(lags1);
numlags2=length(lags2);
for i=1:length(lags1)
coef_1{i}=coef0;
end
for i=1:length(lags2)
coef_2{i}=coef0;
end
Mdl_1 = varm('AR',coef_1,'Lags',lags1);
EstMdl_1 = estimate(Mdl_1,Y,'Y0',Y0);
gctest(EstMdl_1)
Mdl_2 = varm('AR',coef_2,'Lags',lags2);
EstMdl_2 = estimate(Mdl_2,Y,'Y0',Y0);
gctest(EstMdl_2) %gctest fails for the second model Mark Goldsworthyhttps://www.mathworks.com/matlabcentral/profile/authors/1698633-mark-goldsworthytag:www.mathworks.com,2005:Question/4690712019-06-26T20:37:25Z2019-06-26T23:57:52ZQuestion about Resource Allocation in MATLABI use confidential data available through a secure server and have been repeatedly encountering the following issue related to the early termination of a Matlab program/M file:
"PBS: job killed: cpus 34.1 exceeded limit 30 (burst)"
If I were to increase the number of CPUs to 40 or even 50, the M file would run for a while (20 minutes or so), and the job would then be killed off with the same message displayed.
The issue is not caused by errors in the M file itself, as the same program runs to completion in about 3-4 hours on my own Mac laptop with only 2 CPUs (when the program is tested on fake/simulated data). The issue (as I perceive it) seems to be caused by insufficient/incorrect resource allocation. However, this justification seems rather surprising as I previously thought that MATLAB is supposed to ``know" the number of available cores. I would really appreciate any suggestions/thoughts on how to get the M file running to completion.
As an addition clarification, I have run into issues with MATLAB though the server before, but in that case, I just requested 3 or 4 CPUs (as opposed to just 1 CPU). Maybe this particular case is different because the program (which searches for all the local maximums of a specific function) is more "computationally intensive"? It certainly has multiple nested for loops. Sherry Wuhttps://www.mathworks.com/matlabcentral/profile/authors/13767686-sherry-wutag:www.mathworks.com,2005:Question/4690882019-06-26T23:38:31Z2019-06-26T23:38:31ZHow to turn off autocomplete in a live scriptI would like to turn off the "autocomplete" feature of the Live Editor. Just in case "autocomplete" is not the correct word for this, see the screenshot, below. I just typed in "p", and in response the Live Editor opened up a pop-up window of suggestions (pade, partfrac, etc.) and displays a suggested completion using the first item in this list (in this case, "pade", so it suggests appending "ade" to the "p" I typed in).
Long story short, I find this feature very disruptive, and I would like to turn it off. How do I do that? Thanks in advance.
Frederick Papazyanhttps://www.mathworks.com/matlabcentral/profile/authors/10931343-frederick-papazyantag:www.mathworks.com,2005:Question/4690652019-06-26T20:05:00Z2019-06-26T23:21:24ZFor loop with really big matrix Hi all,
I am searching through a big matrix file (>800mb) and tried to loop through that matrix but it take a massive amount of time. I wonder if are there any method to run a simple for loop in this "big data" matrix. My code is at belown
clearvars;
load('landorocean_250_W.mat')
tA_world = tall(A_world);
tx_world = tall(x_world);
ty_world = tall(y_world);
[m_1,n_1]=size(A_world);
for i=1:m_1
for j=1:n_1
if gather(tA_world(i,j) == -32768)
island_250m_1(i,j)=0;
else
island_250m_1(i,j)=1;
end
end
end
Thank you for your time,
Sincerely, Trung Ngohttps://www.mathworks.com/matlabcentral/profile/authors/8932832-trung-ngotag:www.mathworks.com,2005:Question/4688672019-06-25T19:14:58Z2019-06-26T23:12:16Zsorting unique date by time.hello,
I have a n*3 data.(entire US stock data) each cloume date are: stock id, date, price.
the date in in the second cloume is repeating for each stock id.
A T1 P1a
A T2 P2a
A T3 P3a
A T4 P4a
B T1 P1a
B T2 P2b
B T3 P3b
B T4 P4b
.... .... ....
i try to arrange data, let first cloume be the date, and firt row be the stock id.
ID =unique (Data(:,1))';
Date = unique(Data(:,2))
and then i have no ideal how to coding .
the data need to be
A B C ...............
T1 P1a P1b P1c ...............
T2 P2a P2b P2c
T3 P3a P3b P3c
T4 P4a P4b P4c
i have no coding experiences before, and to try the learn the matlab.
thanks for your time
HAOLUN TIANhttps://www.mathworks.com/matlabcentral/profile/authors/15708050-haolun-tiantag:www.mathworks.com,2005:Question/4688992019-06-26T02:08:55Z2019-06-26T23:11:58ZUsing animatedline in Matlab App Designer?Hey everyone,
I am attempting to make a matlab app that is able to plot live data from my serial port. The data comes in separated with commas and is parsed accordingly (still in its early stages). I was able to get this code to work in the normal matlab code envirnment, shown below:
clear all;
delete(instrfindall);
clear;
close all;
clc;
s = serial('COM11', 'BaudRate',115200);
fopen(s);
voltage = 0;
t = 0;
y = 1;
data = fscanf(s);
data = convertCharsToStrings(data);
data = strsplit(data, ',');
TIME(y,1) = str2double(data(1));
VAR1(y,1) = str2double(data(2));
VAR2(y,1) = str2double(data(3));
h = animatedline(TIME(y,1),VAR1(y,1));
h2 = animatedline(TIME(y,1),VAR2(y,1));
xlim([TIME(y,1) TIME(y,1)+20]);
ylim([-1.2 1.2]);
grid on
title("Some Sine Waves");
xlabel("Time [sec]");
ylabel("Value");
tic
while t <= 200
y= y+1;
data = fscanf(s);
data = convertCharsToStrings(data);
data = strsplit(data, ',');
TIME(y,1) = str2double(data(1));
VAR1(y,1) = str2double(data(2));
VAR2(y,1) = str2double(data(3));
addpoints(h, TIME(y,1), VAR1(y,1));
addpoints(h2, TIME(y,1), VAR2(y,1));
xlim([TIME(y,1)-20 TIME(y,1)+4])
%y= y+1;
t=t+0.05;
drawnow
end
toc
fclose(s);
delete(s);
clear s;
This code works and will plot the data. I tried some other methods and the matlab program started to lag very badly, especially after running for 20+ seconds.
Using this code, I tried to apply it to the Matlab App Designer and this is where I am having trouble. The code "error" I am getting below is...
Reference to non-existent field 'UIAxes'
which makes no sense because that is my figure title. This happens right as I define the "animatedline" function. I know other people are having similar problems. When I push a button, the code gets executed. The code in my matlab app designer code window is below:
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
Apollo matlab.ui.Figure
Button matlab.ui.control.Button
UIAxis matlab.ui.control.UIAxes
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
end
% Button pushed function: Button
function ButtonPushed(app, event)
clear all;
delete(instrfindall);
clear;
close all;
clc;
s = serial('COM11', 'BaudRate',115200);
fopen(s);
t = 0;
y = 1;
data = fscanf(s);
data = convertCharsToStrings(data);
data = strsplit(data, ',');
app.TIME(y,1) = str2double(data(1));
app.VAR1(y,1) = str2double(data(2));
app.VAR2(y,1) = str2double(data(3));
app.h = animatedline(app.UIAxis, app.TIME(y,1),app.VAR1(y,1));
app.h2 = animatedline(app.UIAxis, app.TIME(y,1),app.VAR2(y,1));
% xlim([TIME(y,1) TIME(y,1)+20]);
% ylim([-1.2 1.2]);
% grid on
% title("Some Sine Waves");
% xlabel("Time [sec]");
% ylabel("Value");
tic
while t <= 200
y= y+1;
data = fscanf(s);
data = convertCharsToStrings(data);
data = strsplit(data, ',');
TIME(y,1) = str2double(data(1));
VAR1(y,1) = str2double(data(2));
VAR2(y,1) = str2double(data(3));
addpoints(h, TIME(y,1), VAR1(y,1));
addpoints(h2, TIME(y,1), VAR2(y,1));
%xlim([TIME(y,1)-20 TIME(y,1)+4])
%y= y+1;
t=t+0.05;
drawnow
end
toc
fclose(s);
delete(s);
clear s;
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create Apollo
app.Apollo = uifigure;
app.Apollo.Position = [100 100 640 480];
app.Apollo.Name = 'UI Figure';
% Create Button
app.Button = uibutton(app.Apollo, 'push');
app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
app.Button.Position = [45 428 100 22];
% Create UIAxis
app.UIAxis = uiaxes(app.Apollo);
title(app.UIAxis, 'SINE WAVE')
xlabel(app.UIAxis, 'X')
ylabel(app.UIAxis, 'Y')
app.UIAxis.PlotBoxAspectRatio = [1 0.571428571428571 0.571428571428571];
app.UIAxis.Position = [83 111 407 261];
end
end
methods (Access = public)
% Construct app
function app = app1
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.Apollo)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.Apollo)
end
end
endJeff Mayshttps://www.mathworks.com/matlabcentral/profile/authors/10140325-jeff-maystag:www.mathworks.com,2005:Question/4127132018-07-30T13:21:25Z2019-06-26T23:10:23ZWindows Laptop Scaling Not Being Recognized With Figure Copy/PasteHi - I am trying to maintain the size of a figure when I paste it into MS PowerPoint 2016 using my laptop screen instead of docked monitor screen. In my code I have set the figure(f) size to:
f.Units = 'centimeters'; f.Position = [f.Position(1) f.Position(2) 24 12];
(I have tried all other units types...but this best describes the size in MS PowerPoint 2016)
This works fine if my docked monitor is the primary monitor. However when my laptop screen in the primary monitor (un-docked or docked) the pasted image comes out half the size.
% Copy Figure Options (default):
% Preserve Information (meta-file if possible) <<<< I do want to maintain this
% Transparent background
% Match figure screen size - checked
get(0, 'monitorPositions')
1 1 1920 1080 % Laptop (primary - matches windows hence no scaling)
-1919 449 1920 1200 % Docked Monitor (secondary - matches windows hence no scaling)
get(0, 'ScreenPixelsPerInch')
96
Form these commands I am showing that scaling is off and I am not running a high DPI screen. Yet the pasted image is still half the size it should be. Note - all windows graphical scaling is set to 100% on both monitors.
Please....any help would be appreciated
Rufus /
MATLAB 2017b /
Windows 10Rufus Harrison-Banfieldhttps://www.mathworks.com/matlabcentral/profile/authors/1306156-rufus-harrison-banfieldtag:www.mathworks.com,2005:Question/4690812019-06-26T21:47:19Z2019-06-26T23:02:01ZMatlab Eigenvalue/Vector wrong?!I am trying to find eigenvalues and vectors of following matrix.
Lsr=[0.0397796877172068 0.0138619531470359 0.0138619531468867 ;
0.0138619531470345 0.0397796877174583 0.0138619531469220;
0.0138619531468881 0.0138619531469388 0.0397796877171021]
[t,el]=eig(Lsr)
But when I reconstruct the matrix with:
X=t*el*t'
I get
X=[0.0403022792872612 0.0124347611687027 0.0147665535551808
0.0124347611687027 0.0406842881257273 0.0143845447169696
0.0147665535551808 0.0143845447169696 0.0383524957387787]
Which is totally off!
Any idea?Meysam Ahmadihttps://www.mathworks.com/matlabcentral/profile/authors/6120434-meysam-ahmaditag:www.mathworks.com,2005:Question/1810822015-03-02T13:34:37Z2019-06-26T22:58:33ZHo w to find the first minimum element in a rowHere i have a 1X6 matrix
y =
682.8333 399.8160 34.2270 46.1800 107.7035 21.5367
what i wanna do is to find the FIRST minimum element
which means if i plot "y" i wanna find first minimum turning point
for this example it must be 34.2270
Thank you.
Chamira Wickramasinghehttps://www.mathworks.com/matlabcentral/profile/authors/6020974-chamira-wickramasinghetag:www.mathworks.com,2005:Question/4690032019-06-26T14:19:23Z2019-06-26T22:57:51ZEdit colorbar of heatmap (string)Hi,
Is it possible to edit the colorbar of a heatmap such that it looks like the following image (rapidly created with paint ;) )
So the values aren't numeric but strings.
Thanks for help!Gerrit Liedtkehttps://www.mathworks.com/matlabcentral/profile/authors/12573007-gerrit-liedtketag:www.mathworks.com,2005:Question/4680422019-06-20T10:11:12Z2019-06-26T22:55:42Zset process noise 1D Constant VelocityHi,
I can define a Kalman filter with the code:
KF = trackingKF ('MotionModel','1D Constant Velocity');
How do I set the process noise? I mean I can set it with e.g:
KF.ProcessNoise=eye(2);
but since the process noise should be a function of one parameter only there should be som other way.
BR/
Per
Per Zetterberghttps://www.mathworks.com/matlabcentral/profile/authors/8612768-per-zetterbergtag:www.mathworks.com,2005:Question/4688932019-06-25T23:35:34Z2019-06-26T22:50:55ZIs it possible to output a NaN from the signal editor block?I thought I had a signal editor outputting a signal which had NaN values for some parts. In a new model I tried to do it again but I only get an error that this is not allowed.
Is it possible to output a NaN from a signal editor and I just have some block/model settings wrong? Or did I imagine that I could do it before?
Thanks!
AdamAdam Shttps://www.mathworks.com/matlabcentral/profile/authors/15720413-adam-stag:www.mathworks.com,2005:Question/4690722019-06-26T20:39:41Z2019-06-26T22:48:38ZHow to fill up a huge/very large matrix, with elements from another matrix in a time efficient way? Hi there,
I am doing some calculations for some graph/network with vertices that have certain connections/edges to each other.
My goal is to set-up a very large matrices with dimensions ranging from roughly 90000x300(works but already takes up ~4.6 seconds to create) up to 9,000,000 (9mln)x30000 elements in an efficient way, such that is does not take forever to fill up the matrix. Most elements are, however, zeros so I tried using sparse matrices, but sparse matrices are not suitable if you want to fill them up element-wise.
The size of the matrices depend on a discretization parameter(delta) that I choose, I need to make it as small as possible, down to 10^-4. My function is now as follows(I use Hungarian notation):
function mZ_j = createZ_j(iN, iP, iD_j, mX, vPA)
% Function that creates design matrix Z_j.
% Dimensions: (n-p)x(p*d_j)+1, d_j can go up to 6, but is 2 on average
% input/starting parametes are:
% delta = 0.0001, s=0.5, T=900(15 min in seconds), d_j=2
iRows = iN-iP; % n:= T/delta, p:=s/delta
iCol = (iP*iD_j);
mZ_j = zeros(iRows,iCol); % (n-p)x(p*d_j) matrix
mX_j = mX(:,vPA); % matrix were elements will be taken from, vPA(size iD_j) has the column indexes
p = iP+1; % indicator for each row; it is an autoregressive process and each row you regress on p lags, but every row you take one next step in time
for i=1:iRows
for j=1:iP
iCStart = ((j-1)*iD_j)+1; iCEnd = j*iD_j;
mZ_j(i,iCStart:iCEnd) = mX_j(p-j,:);
end
p = p+1;
end
Does anyone see or know how I can assign the elements from mX_j more efficiently to mZ_j? The operations themselve do not take a lot time, it is just the amount of iterations that it has to do.
Thanks!Jeroenhttps://www.mathworks.com/matlabcentral/profile/authors/13531204-jeroentag:www.mathworks.com,2005:Question/4690792019-06-26T21:32:25Z2019-06-26T22:47:04ZKinect V2 Depth ChangesHi All,
I am currently working with the Kinect V2 to develop a method of tracking respiratory motion.
How can I model and plot the depth changes over time? From looking into the array the depth image stores, the depth seems to be an index between the height and width.
For simplicity I want to plot the depth changes of a 5x5 pixel square in the center of the screen over 300 frames, so roughly 10 seconds. (I'll change the frequency to fixed 10 Hz later) but right now i'm stuck on the basics.
Any help would be appreciated!
Thank you in advance.Anthony Fotihttps://www.mathworks.com/matlabcentral/profile/authors/6690508-anthony-fotitag:www.mathworks.com,2005:Question/4689952019-06-26T13:33:25Z2019-06-26T22:42:11ZWhy should i not use msgbox in App Designer?Why should i not use msgbox in App Designer?
https://de.mathworks.com/help/matlab/ref/msgbox.html
The site is saying:
If you are using App Designer or creating apps with the uifigure function, then use uialert instead. For more information, see Migrating GUIDE Apps to App Designer.
msgbox is a tool that i know and it works fine for me. Why should i not use it?
thanks!
Christian Tieberhttps://www.mathworks.com/matlabcentral/profile/authors/12488560-christian-tiebertag:www.mathworks.com,2005:Question/4690752019-06-26T21:08:33Z2019-06-26T22:29:02ZHow do I export a vector to workspace in simulink?I'm trying to model a household appliance in simulink. When the simulation ends, I need the model to output a vector to the workspace which contains power loads corresponding to simulation times. I've started with trying to implement as simple a model as I can, shown below.
The idea here is to just send simulation time to a function which appends the simulation time to a vector containing all simulation times. Basically, if the simulation stop time is 10, what I want from this model is AllTimes = [1, 2, 3, ... 10].
I've set the model to run an initialization function, which contains the following:
times = [];
The MATLAB function block contains the following:
function times = fcn(currentTime)
times = [times, currentTime];
times = time;
Simulink complains that:
The issue, as I understand it, is that "time" is declared outside fcn's scope. I've tried the following tweaks to fix this:
function times = fcn(currentTime)
if ~exist('vect')
vect = [];
end
times = currentTime;
function times = fcn(currentTime)
times = evalin('base', [times, currentTime]);
times = currentTime;
function times = fcn(currentTime)
assignin('base', times, [times, currentTime])
times = currentTime;
However, none of these have worked.
I also tried importing the function times from the workspace and passing it as an argument to fcn, like so:
function times = fcn(currentTime, times)
times = [times, currentTime];
times = currentTime;
However, this throws the error:
Unfortunately, I have very limited knowledge of MATLAB and even less knowledge of simulink. If anyone has any advice I would very much appreciate help.Shiloh Greerhttps://www.mathworks.com/matlabcentral/profile/authors/13498832-shiloh-greertag:www.mathworks.com,2005:Question/4690772019-06-26T21:23:57Z2019-06-26T22:12:27ZModify text in a columnDear all, I want to modify just the first column of a file, removing the letters and keeping the numbers. The columns contain string like d200n-h. How it is possible?
Thanks,
MarcoMarco Settehttps://www.mathworks.com/matlabcentral/profile/authors/12996838-marco-settetag:www.mathworks.com,2005:Question/4685942019-06-24T11:32:08Z2019-06-26T22:11:24ZHow can i build a 3 phase inverter with simscape, which the output voltage with rise and fall time?How can i build a 3 phase inverter with simscape, which the output voltage with rise and fall time?
Normally the IGBT block are idea,l so the output voltage is just a step.Mingyuan Sunhttps://www.mathworks.com/matlabcentral/profile/authors/10485123-mingyuan-suntag:www.mathworks.com,2005:Question/4690832019-06-26T22:02:12Z2019-06-26T22:10:43ZData extract from graph.I have a plot I created in matlab using excel data. I would like my code to provide a Y value for the X value that I provide. Is this possible? Please note that i cannot look for the Y value, the code should automatically assign the Y value from the graph for provided X value.
Thanks for the Help.Vikas Vasudevanhttps://www.mathworks.com/matlabcentral/profile/authors/15247653-vikas-vasudevantag:www.mathworks.com,2005:Question/4650572019-06-01T10:05:19Z2019-06-26T22:07:10ZHow to change maxfun evals in fsolve 'levenberg-marquardt' algorith. I am using f solve to get the solution of a non linear system equation but i get the error:
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunEvals = 3500 (the default value).
I am trying to manual change the limit by coding:
options = optimoptions(@fsolve,'Algorithm','levenberg-marquardt','MaxFunEvals',15000)
as per manual but with no luck.
Can you help me? Morevoer is is "bad sign" for the stability of the system that the itterations are not enough to solve it?Michael Gkouvakishttps://www.mathworks.com/matlabcentral/profile/authors/14800261-michael-gkouvakistag:www.mathworks.com,2005:Question/4687932019-06-25T11:31:13Z2019-06-26T22:05:42ZBlank plot in matlabhello can you please help me?? when i type this code i only get a balnk plot
i don`t know where is my mistake
the code
sigma0=0;
el= 0.5;
L= 1 ;
h= 0.5 ;
a= 1;
N= 3;
g=10;
rho=1000;
Z0=0;
t=0:0.01:5;
x=0:0.02:el;
y=0:0.02:L;
[X,Y]=meshgrid (x,y);
sigma=0;
T=3*pi/4;
for n=0:N
for m=0:N
A=pi*((m/el)^(2)+(n/L)^(2))^(0.5);
B=(g*A+(sigma/rho)*A^3)*atan(A*h);
C=B^(0.5);
Z=a*cos(C.*T).*cos((m*pi/el).*X).*cos((n*pi/L).*Y);
Zs=Z0+Z;
Z0=Zs;
end
end
m=3;
n=4;
A=pi*((m/el)^(2)+(n/L)^(2))^(0.5);
B0=(g*A+(sigma0./rho)*A^3)*atan(A*h);
C0=(B0.^(0.5));
Z0=(a.*cos(C0.*T)).*cos((m*pi/el).*X).*(cos((n*pi/L).*Y));
figure
subplot(221)
plot(t,length(Z0));
xlabel(' temps s');
ylabel(' élévation z(x,y)y');
title(' sans tension superficielle');
legend('sigma0')MOUNIBA REDAHhttps://www.mathworks.com/matlabcentral/profile/authors/15717627-mouniba-redahtag:www.mathworks.com,2005:Question/4690782019-06-26T21:24:41Z2019-06-26T22:05:40ZExtract rows with a range of valuesI have two tables. The first table (tab1) has column with ids. We call it ID. The second table (tab2) also has ids which is called ID as well. I am trying to extract all the rows in tab2 that has at least one match of ID from tab1. Following is what I have tried:
rev_table=tab2(tab1.ID,:);
Could someone help please?Syeda Amberinhttps://www.mathworks.com/matlabcentral/profile/authors/12017818-syeda-amberintag:www.mathworks.com,2005:Question/912182013-10-23T13:57:38Z2019-06-26T21:57:41ZCapture mouse location beyond screen coordinates Hi Jan,
I am writing you because you seem to answer almost every question I search for. Now that my search is not producing anything, I thought I might go ahead and try you now . My question regards mouse position. I am currently coding a program where I would like the mouse to 1)allow the mouse to go off-screen and 2)record its positions while there (and invisible).
The reason I need this functionality: I am programming a game where I am trying to make the user move the mouse a lot to produce just a little movement in an object. That means for a large change in mouse position, I am only allowing the object they are controlling to move a bit. Because large position changes will result only in small motion changes, the resolution of the screen does not provide me with the range I need to give the user the ability to move the object in a wide range, as I would like. I want them to be able to laboriously drag the mouse through a large range on the table to produce the movement.
The problem, I cannot find any way to track the mouse in a range that is larger than the screen resolution, either with MATLAB or with Psychtoolbox.
Any ideas?
Thanks,
ChachaChachahttps://www.mathworks.com/matlabcentral/profile/authors/4655262-chachatag:www.mathworks.com,2005:Question/4690822019-06-26T21:56:33Z2019-06-26T21:56:33ZHow do I find amplitude of a signal within one second interval?Ive already plotted the graphs and even found the amplitude. But now, I would like to calculate the amplitude within a window of one second. Please help me. Below is my code:
%% Analysis of EMG data
%An EMG signal has a frequency between 0 to 500 Hz; but the usable
%frequency is between 50 and 150 Hz.
% EMG signal is produced using an instrument called the electromyograph that records electric activity
% produced by muscles.
% The amplitude for surface EMG signals is within the range of 0 to 10 mV.
% sEMG (surace EMG) signals tend to have a DC bias, therefore a high pass
% filter is applied to a cutoff frequency of 50Hz. This high pass filter
% removes any DC bias.
% The root mean-square (RMS): calculated by finding the square root of: squaring each data point,
%summing the squares, dividing the sum by the number of observations.
%RMS value of a signal is a measure of the power of the signal and it
%reflects on the activity in the motor unit during contraction.
% This makes RMS useful in producing waveforms.
% Amplitude of an EMG signal is random with Gaussian Distribution/
% RMS and MA are two parameters used to measure the amplitude.
% MA short for: Mean Absolute value: is a mean of the absolute value of
% EMG signal
% MA is a measure of the area under the rectified EMG.
% In order to calculate MA remove all of the negative phases of the raw EMG
% This is known as: half-wave rectification.
% The MA and RMS provide an estimate of the amplitude of the raw EMG signal.
t = EMGSampleData(:,1);
y1 = EMGSampleData(:,2);
N = length(y1);% find the length of the data per second
ls = size(y1); %% size
f = 1/N;% find the sampling rate or frequency
%Note: sampling frequency should be at least twice the incoming signal.
fs = 3000;
T = 1/fs % period between each sample
t1 = (0 : N-1) *T;
t = (0:1:length(y1)-1)/fs; % sampling period
% nyquist frequency is half of the sampling rate of a signal. Also known as:
% folding frequency.
Nyquist = fs/2;
figure;
%
subplot (3,1,1), plot(t,y1,'b');
title ('EMG signal of single muscle 40 month old patient ');
xlabel ('time (sec)');
ylabel ('Amplitute (V)');
grid on;
Y= abs(fft(y1));
Y(1) = [];
power = abs(Y(1:N/2)).^2;
nyquist = 500;
freq = (1:N/2)/(N/2)*nyquist;
subplot(212), plot(freq,power), grid on
xlabel('Sample number (in Frequency)')
ylabel('Power spectrumen');
title({'Single-sided Power spectrum' ...
' (Frequency in shown on a log scale)'});
axis tight
%%% RMS of the signal
rms_y1 = sqrt(mean(y1.^2));
msgbox(strcat('RMS of EMG signal is = ',mat2str(rms_y1), ''));
rms_emg = rms (y1);
%%%%% MA of the signal
ma_y1 = abs(mean(y1));
msgbox(strcat('MA of EMG signal is = ',mat2str(ma_y1), ''));
%remove any DC offset of the signal
% use the detrend function.
% It subtracts the mean or a best-fit line from data.
y2 = detrend(y1); %% y2 is the singal after DC offset removed.
figure;
rec_y = abs(y2);
plot (rec_y);
xlabel('Sample number (in Frequency)')
ylabel('Rectified EMG signal');
title({'Rectified EMG signal' ...
' (Frequency shown on a log scale)'});
figure;
xdft = fft(y1);
xdft = xdft(1:N/2+1);
psdx = (1/(fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:fs/length(y1):fs/2;
plot(freq,10*log10(psdx))
grid on
title(' Power spectrum FFT')
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)')
%amplitude of the entire signal
amplitude = max(y2(:)) - min(y2(:))
%%% DFT to describe the signal in the frequency
NFFT = 2 ^ nextpow2(N);
% The reason I used this function above:
%The execution time for fft depends on the length of the transform.
% It is fastest for powers of two. It is almost as fast for lengths that
%have only small prime factors. It is typically several times slower for
%lengths that are prime or which have large prime factors.
Y = fft(y1, NFFT) / N;
f = (fs / 2 * linspace(0, 1, NFFT / 2+1))'; % Vector containing frequencies in Hz
amp = ( 2 * abs(Y(1: NFFT / 2+1))) % Vector containing corresponding amplitudes
figure;
plot (f, amp);
title ('plot single-sided amplitude spectrum of the EMG signal')
xlabel ('frequency (Hz)')
ylabel ('|y(f)|')
grid on;Amer Yaghihttps://www.mathworks.com/matlabcentral/profile/authors/10978548-amer-yaghitag:www.mathworks.com,2005:Question/4690762019-06-26T21:10:51Z2019-06-26T21:39:53ZRe-download Matlab to my new computerPurchased and downloaded Matlab 2013 on my old computer. I need to upload to my new computer. Can I do this?
Thank you,
Noelnoel mantohttps://www.mathworks.com/matlabcentral/profile/authors/3772777-noel-mantotag:www.mathworks.com,2005:Question/4074652018-06-26T09:54:55Z2019-06-26T21:38:36ZBar plot with color mapI have a table with x rows and two columns: fold change and p-value.
I'd like to make a bar plot such that the length of the bars will be according to the fold change value, and the color of each according to it's p-value (therefore colormap should be presented as well)
I couldn't figure out how i can do such thing, so if it's indeed possible on Matlab i would appreciate your help. Thanks!Rotem Katzirhttps://www.mathworks.com/matlabcentral/profile/authors/5688779-rotem-katzirtag:www.mathworks.com,2005:Question/1471032014-08-11T00:59:48Z2019-06-26T21:37:54Zincrement two values in a single for loopI was just wondering if there was a way to increment two variables simultaneously in a single for loop?
for example i want to increment
i = 1:1:n-times
but at the same time
j=1:1:m-times
in a single for loop
Duncanhttps://www.mathworks.com/matlabcentral/profile/authors/5351214-duncantag:www.mathworks.com,2005:Question/4690802019-06-26T21:33:33Z2019-06-26T21:33:33ZTrying to manually set rgb values of cells equal to 0 on contourf figureI am attempting to manually set the rgb values on the displayed heat map/2D graph created by contourf, taking data from my input array (a 33477x13 array) to a dark blue if the cell value is equal to 0. How would I do this?
Here is the code:
function [SMPS_data]=Contourf(A)
i=1;
while i<3
start_date = {'5-June-19 0:00','26-May-19 0:01'};
t1 = datetime(2019,5,26,0,0,0);
t2 = datetime(2019,6,4,0,0,0);
dates=t1:minutes(10):t2;
duration_min = numel(dates)*10;
SMPS_timestep = [0:10:duration_min];
colormap(jet)
SMPS_data=[A];
x=zeros(1,length(SMPS_data));
for j=1:length(SMPS_data)
x(1,j) = j/6;
end
y = [11.5; 15.4; 20.5; 27.4; 36.5; 48.7; 64.9; 86.6; 115.5; 154; 205.4; 273.8; 365.2];
z_o=zeros(1,numel(x));
z_r= SMPS_data(1:end,2:end).';
z = [z_o;z_r];
[X,Y] = meshgrid(x,y);
v=logspace(-1,15,500);
[X,Y] = meshgrid(x, y);
figure
[C,h] = contourf(X,Y,griddata(x,y,z,X,Y,'natural'),v);
C(C==0)
set(gca,'yscale','log')
ylim([-1 250]);
str=sprintf('Time (h), t(0) = %s', start_date{2});
xlabel(str)
ylabel('Particle diameter (\mum)')
set(h,'LineStyle','none');
c =colorbar;
caxis([0 2500])
hl = ylabel(c, 'dN/dlogDp #/cm^{-3}');
set(hl, 'Rotation',90);
set(c,'FontSize',12,'LineWidth',1.5)
set(gca,'FontSize',12,'LineWidth',1.5)
set(gca,'TickDir','out')
set(gca,'XTickMode','auto')
%set(gca, 'XTick',[0 6 12 18 24 30 36 42 48 54])
set(gca, 'XTickLabel',{'5/26','5/27','5/28','5/29','5/30','5/31','6/1','6/2','6/3','6/4'})
set(gca, 'YTick',[10 30 50 100 150 200])
set(gca, 'YTickLabel',{'10','30','50','100','150','200'})
box off
i=i+1;
end
endChristianhttps://www.mathworks.com/matlabcentral/profile/authors/15725648-christiantag:www.mathworks.com,2005:Question/2844862016-05-16T19:03:57Z2019-06-26T21:29:45ZSplitapply, each data of group in a new figure/plotHi all,
I am using the function splitapply. However I have problems with plotting each group in another figure (or hide one or more groups).
Currently I am using (attachment with .mat-file):
hold on
splitapply(@(difference_mean,difference)plot(difference_mean,difference,'o'),difference_mean,difference,G);
It would be the best to create three seperate figures with each group another figure. Alternatively, create 3 times the same figure and delete the other data.
Can somebody provide me with de solution :)?
Greetings,
MartijnKFrenkiehttps://www.mathworks.com/matlabcentral/profile/authors/3755731-kfrenkietag:www.mathworks.com,2005:Question/3468312017-06-29T18:34:37Z2019-06-26T21:21:27ZHow can I change the resolution of kinect V2 in matlab?Kinect V2 color stream supported format is : 1920x1080. But kinect V2 depth stream format is : 512x424. Now when I start live steam for both sensors then they have different sizes because of different resolution. I cant resize them, because I need coordinates . so when I resize using Imresize(),the coordinates are not matched. I already read matlab documentation.They said hardware only supports this two format respectively.Now How can i do this in code so that both stream have the same resolution. I tried two days long but failed.
sufian ahmedhttps://www.mathworks.com/matlabcentral/profile/authors/10225144-sufian-ahmedtag:www.mathworks.com,2005:Question/4685002019-06-23T20:04:00Z2019-06-26T21:18:39ZPushButton repeat previously generated audio sample (with other pushbutton)I will need to use the script below for a listening test. is still not as I need it and the deadline is approaching so I decided to come here and find out if someone can help. (Thanks in advance!)
Information about the script: I am using GUI; among other tools that are not relevant for this specific problem I have included 2 pushbuttons which are causing me some problems. One pushbutton is supposed to play one audio sample (randomly) out of 3 existing audio samples. The other pushbutton is supposed to play the sample again if the listener needs it.
My problems are due to this:
1- Each sample needs to be played randomly but the user needs to be able to listen to it again if he wants. I would like to use the "REPEAT" button for that.
2- I am using a different GUI for each of the three audio samples that will be evaluated by the listener (probably the worst idea ever as the GUIs are exactly the same, but it's how I managed to make it work so far). Each GUI has a "NEXT" button to close the old GUI and open the next one.
When the user changes from the first GUI to the second, the previously evaluated sample, must not be included in the random operation as they can't evaluate the same audio sample twice during the test.
------> I am not being able to solve these two issues and the deadline is almost here. PLEASE I need some help.
Thank you very much!
This is the code I am using for the pushbutton PLAY at the moment:
a = audioread('guitar.wav');
b = audioread('cinematic.wav');
c = audioread('epicorchestra.wav');
numsounds = 3;
sounds = { a; b; c;}
orders=randperm(numsounds,3); % random order
%pick one of the positions in "orders"
location = randi(length(orders));
% extract wave data from line identified by "locations" in column one.
wavData = sounds{location, 1};
% sampling frequency (same for all audio files)
sf = 48000
% play audio sample with that wavdata and corresponding sampling
% frequency
soundsc(wavData, sf);
Ana Camposhttps://www.mathworks.com/matlabcentral/profile/authors/9760934-ana-campostag:www.mathworks.com,2005:Question/4690732019-06-26T20:53:45Z2019-06-26T21:15:18ZSave vector to class propertiesGreetings,
I am trying to build a class that would extract information from .csv files and save these information to the properties of the class. Attached is the example of the file.
Here are my code:
classdef post_processing
properties
data_folder = 'path\path'
filename
time
voltage
norm_voltage
record_length
state_level_high
state_level_low
end
methods
function extract_info(obj)
addpath(obj.data_folder);
filename = 'test.csv';
data = readmatrix(filename);
horizontal_offset = data(6,2); %seconds
sample_interval = data(2,2);%seconds
record_length = data(1,2); %points
time = data(:,4)-horizontal_offset; %seconds
voltage = data(:,5); %volt
norm_voltage = data(:,5)/max(data(:,5));%arb. units
obj.time = time;
obj.voltage = voltage;
obj.norm_voltage = norm_voltage;
obj.record_length = record_length;
end
end
end
I called my script:
test = post_processing;
extract_info(test);
test
give output
I do not know why my properties are not updated when I called my extract_info function.
Thanks for the help.novelphyhttps://www.mathworks.com/matlabcentral/profile/authors/12897852-novelphy