https://nl.mathworks.com/matlabcentral/answers/questions MATLAB Answers — New Questions 2021-01-24T06:52:13Z tag:nl.mathworks.com,2005:Question/725372 2021-01-24T06:52:13Z 2021-01-24T06:52:13Z Can i do Wavelet coherence in MATLAB R2014a ? I'm using MATLAB R2014a and couldn't able to use the function ' wcoherence'. When I run the program it shows: Undefined function 'wcoherence' for input arguments of type 'double'. When I used the old function 'wcoher' it works. What should I do to use 'wcoherence' in R2014a? sakt hid https://nl.mathworks.com/matlabcentral/profile/authors/21181001 tag:nl.mathworks.com,2005:Question/725172 2021-01-23T19:45:18Z 2021-01-24T06:50:30Z Plotting a smooth curve from points I'm trying to plot a smooth line for 6 points in such a way that slope at each is zero. I have successfully achieved it for middle points using 'pchip' but I also want it for extreme points i.e. x=0 and x=15 which I am unable to do while using 'pchip'. Here is my code clear clc x = [0;3;6;9;12;15]; y = [0;1.9190;-3.2287;3.5133;-2.6825;1]; xi = linspace(min(x), max(x), 150); % Evenly-Spaced Interpolation Vector yi = interp1(x, y, xi, 'pchip'); figure plot(x, y, 'b') hold on plot(xi, yi, '-r') hold off grid xlabel('X') ylabel('Y') legend('Original Data', 'Interpolation', 'Location', 'NE') Osama Anwar https://nl.mathworks.com/matlabcentral/profile/authors/20535048 tag:nl.mathworks.com,2005:Question/716688 2021-01-14T09:02:58Z 2021-01-24T06:46:08Z how can i load into MATLAB specific pixels of a .tiff file? I need to load into MATLAB a lot of .tiff files (a few thousands), and to speed the process I wanted to read only the interesting pixels (or index) from any file. is there a way to do it without loading the full files? Orel Levy https://nl.mathworks.com/matlabcentral/profile/authors/20679606 tag:nl.mathworks.com,2005:Question/722773 2021-01-21T06:45:56Z 2021-01-24T06:42:55Z How to fit a dress on human body automatically ? How to fit a dress on human body automatically ? Selva Karna https://nl.mathworks.com/matlabcentral/profile/authors/4733665 tag:nl.mathworks.com,2005:Question/725237 2021-01-23T22:53:25Z 2021-01-24T06:42:25Z dynamically save a matrix to a structure I have a loop that evaluates a matrix X for each scenario. The size of this matrix X changes at each iteration, and the values too. I would like to make a structure X.1, X.2 etc to X.(n), and save the result X. When I do eval(['[Z.SET'num2str(J) ']= (Xtmp);']); X.1 gets overwritten by X.2, what I mean is that at first I have X.1 with the desired X matrix, but at the next loop, X.1 is no longer there and there is X.2 (with the corresponding X matrix). How can I “save” the X.1 so that it doesn’t get overwritten? A https://nl.mathworks.com/matlabcentral/profile/authors/12970920 tag:nl.mathworks.com,2005:Question/725272 2021-01-24T00:23:04Z 2021-01-24T06:41:48Z In an assignment A(I) = B, the number of elements in B and I must be the same Hi, I need help. What should i do for fix this error function dydt = fix_reaksi_tumor_glioma(t,y) dydt = zeros(size(y)); % Parameter model pertumbuhan glioma (1 g/ml = 10^3 mg/ml) aT = 1.575; % ml^2 g^-2 day^-1 KT = 2; % g/ml dTI = 0.072; % day^-1 aTI = 3*10^-4; % day^-1 dT = 1*10^-4; % day^-1 dI = 0.01; % day^-1 as = 0.7; % day^-1 v = 0.7; % day^-1 dTo = 1; % day^-1 ao = 20; % day^-1 omin = 8.00*10^-4; % g/ml o0 = 1.6*10^-3; % g/ml do1 = 0.01; % day^-1 do2 = 0.00625; % day^-1 dTT = 0.72; % day^-1 f_glukosa = omin*sin(6*pi*t); %Asupan glukosa T = y(1); % pertumbuhan sel glioma (Tumor) B = y(2); % konsetrasi glukosa dalam otak (obrain) I = y(3); % aktivitas sistem kekebalan tubuh (imune) S = y(4); % konsentrasi glukosa dalam serum (oserum) dydt(1)= aT*B*T*(1-T/KT) - dT*T - dTI*T*I; dydt(2)= ao*(S-B) - dTo*T*B - (do1+as*(v+I))*B; dydt(3)= as*(v+I)*B + aTI*T*I - dI*I - dTT*T*I; dydt(4)= ao*(B-S) + f_glukosa - do2*S; dydt=[dydt(1); dydt(2); dydt(3); dydt(4)]; I get error Error in fix_reaksi_tumor_glioma (line 33) dydt(4)= ao*(B-S) + f_glukosa - do2*S; K>> dydt(4)= ao*(B-S) + f_glukosa - do2*S; In an assignment A(I) = B, the number of elements in B and I must be the same. Lutfi Adam https://nl.mathworks.com/matlabcentral/profile/authors/21192163 tag:nl.mathworks.com,2005:Question/718525 2021-01-16T11:25:26Z 2021-01-24T06:38:44Z Use of Matlab's OCR to recognize Math Equation I'm trying to use Matlab's ocr to recognize math equations but the result was some unknown characters. This is my input: and the output was: How can I improve or solve this problem? I just followed the code on the ocr documentaions and use the 'MathEquation' Language here is the code: x = imread('1.png'); results = ocr(x,'Language', 'MathEquation') recognized = results.Text; figure; imshow(x); text(600,150, recognized,'BackgroundColor', [1 1 1]); Wifraim Neil San Miguel https://nl.mathworks.com/matlabcentral/profile/authors/16181980 tag:nl.mathworks.com,2005:Question/723768 2021-01-22T07:38:18Z 2021-01-24T06:37:36Z How to extract image roi [non scale roi] and how to assign another image roi location ?[ non-scale roi area ? How to extract image roi [non scale roi from dora image] and how to assign another image roi location ?[ non-scale roi area --to the bag] Both images are different rows and columns ? ? Expect like below image: Selva Karna https://nl.mathworks.com/matlabcentral/profile/authors/4733665 tag:nl.mathworks.com,2005:Question/421871 2018-10-02T19:33:48Z 2021-01-24T06:36:34Z new version of "newtr" function Hi everybody I got a code (SRGTSToolbox) that has been written with old version of MATLAB. This is a part of that code: % CALCULATE ACTUAL ERROR w1 = p(:,used)'; a1 = radbas(dist(w1,p)*b); [w2,b2] = solvelin2(a1,t); a2 = w2*a1 + b2*ones(1,q); sse = sumsqr(t-a2); % Start tr = newtr(mn,'perf'); tr.perf(1) = sumsqr(t); tr.perf(2) = sse; As can be seen there is a function called "newtr". What's the updated version of this function in MATLAB 2015? This is a part of radial basis neural network code. Thanks Andrea Vang https://nl.mathworks.com/matlabcentral/profile/authors/13207709 tag:nl.mathworks.com,2005:Question/721084 2021-01-19T12:06:54Z 2021-01-24T06:35:21Z How to formulate elegantly and performant functions that depend on a lot of input variables Hello, I am not new to MATLAB. However, I have the following problem: If I have a function e.g.: output = f(in1,in2,in3,in4,in5,in6,...) which depends on a lot of input variables. How can I design it as elegant as possible but at the same time performant? If I use a strcut e.g. input.in1 input.in2 input.in3 ... I can formulate the function nice and short: output = f(input) But the problem is that the variable naming is fixed for the input as well as in the function. Furthermore, calling values from a struct is slow, so in the function they have to be read first: function [output] = f(input) in1 = input.in1 in2 = input.in2 in3 = input.in3 ... % calculations with in1,in2,in3,... end I also know that you should not write a function with so many input variables, yet it happens. How do you handle such cases? Ferdinand Breit https://nl.mathworks.com/matlabcentral/profile/authors/9184835 tag:nl.mathworks.com,2005:Question/216563 2015-05-13T15:26:02Z 2021-01-24T06:31:43Z How to write fast fourier transform function without using fft function ? function [A]=DFT(x) N=length(x); for k=1:N A(k)=0; for n=1:N A(k)=A(k)+x(n).*exp((-1j).*2.*pi.*(n-1).*(k-1)./N); end end Nur Kaynar https://nl.mathworks.com/matlabcentral/profile/authors/6505303 tag:nl.mathworks.com,2005:Question/725127 2021-01-23T18:19:39Z 2021-01-24T06:29:26Z Not enough input arguments. Hi, i am having issue to run a VAR model were the following error is flagged: >> VARmodel Not enough input arguments. Error in VARmodel (line 33) [nobs, nvar] = size(ENDO); Should I have to quote nobs and nvar? economics student https://nl.mathworks.com/matlabcentral/profile/authors/7041546 tag:nl.mathworks.com,2005:Question/725367 2021-01-24T06:28:23Z 2021-01-24T06:28:23Z Fastest way to find text keywords out of large amount of textual news sentences? Hello, I have a database containing over 900,000 line of news. And I want to scan these lines of texts for certain keyword. I tried tic; strfind(newsDb.SingleNewline, kws{1}); toc tic; contains(newsDb.SingleNewline, kws{1}); toc both takes over 0.003 sec for search in one keyword in one news line. If I want to create a new database with over 20,000 keywords, then it would take 900000 * 20000 * 0.003 / 60 / 60 / 24 over 600 days to do this. :( Anyone has perhaps an idea how to to this within perhaps one-two day? Thank you very much Song Decn https://nl.mathworks.com/matlabcentral/profile/authors/10395652 tag:nl.mathworks.com,2005:Question/280414 2016-04-22T12:53:38Z 2021-01-24T06:27:02Z LaTeX in Live Scripts - Using \matrix I want to use the new Live Scripts feature to include a matrix. The usual way of doing this: \begin{pmatrix} A & B \\ C & D \end{pmatrix} doesn't work. The documentation says to use the \matrix command. This works for a row vector: \pmatrix{a & b} but not for a column vector or full matrix, i.e. \matrix{a & b \\ c & d} How would I render a full matrix in the equation editor within live scripts? Alexander https://nl.mathworks.com/matlabcentral/profile/authors/4188542 tag:nl.mathworks.com,2005:Question/461567 2019-05-12T02:26:31Z 2021-01-24T06:26:20Z Fit Data to a Polar Equation This is a little abstract, but I have data that is represented of some form of polar equation, and I would like to fit a polar equation to this data as accurately as possible. I don't want to fit it to a circle nor do I want to fit it to an ellipse. I want to fit it to a general polar function. Basically, what I am thinking of, is an analog of a polyfit of a high number to very accurately fit a cartesian function in polar coordinates. Just wondering if something like this exists in matlab. John Shackleton https://nl.mathworks.com/matlabcentral/profile/authors/14657992 tag:nl.mathworks.com,2005:Question/724927 2021-01-23T13:31:33Z 2021-01-24T06:23:20Z Unknown File/Folder in directory HI, I'm one of the enw users of Matlab. I'm Having some problem in folder and sub folder reading...... Look at this Code.... Name = '.\train20X20\' Main_File = dir(fullfile(Name)); Normal access to a folder, but this folder has 34 sub folder in it but when I compile this line, on the (Workspace) Tab the variable Main_File shows that there are 36 folders in it. What does this mean, I dont Understand. In the Main folder there are 34 subfolders having 10 images each. what is wrong. after that when i try to make a loop to access the subfolder using there names it shows an error message. I tried bothg with Curly Brackets and Small Brackets but the same message appeared. Few Monthes Earliar i worked on something similar, the function worked perfectly but this time it's not working i dont know what wrong. Mir AbdulRehman https://nl.mathworks.com/matlabcentral/profile/authors/17939352 tag:nl.mathworks.com,2005:Question/725352 2021-01-24T04:37:28Z 2021-01-24T06:15:02Z read the first 3 lines of a file and extract variables without reading the rest Hello, I have a file "toread.txt" have following lines, Profile=" time= 0.123456 " VARIABLES = "X" "Y" "Z" Z="XY" X= 10,Y= 10, 0.00000 0.00000 0.00000E+00 0.01953 0.00000 0.00000E+00 How could I read and extract the first three variables, t = 0.123456, X = 10, and Y = 10, without reading the rest of the document? Thanks! Lei Zeng https://nl.mathworks.com/matlabcentral/profile/authors/16066587 tag:nl.mathworks.com,2005:Question/222657 2015-06-05T16:19:43Z 2021-01-24T06:04:43Z How to control for continuous covariates in multiple regression If I have two predictor variables, say x1 x2, and would like to see what the effect of x1 is on the dependent variable y, how can I remove the effect of x2? Also how can I visualise this in plot? Thanks in advance D https://nl.mathworks.com/matlabcentral/profile/authors/4642374 tag:nl.mathworks.com,2005:Question/343209 2017-06-03T19:46:41Z 2021-01-24T06:00:42Z Find distance between nodes Hi i have a dataset of 1853 rows and 2 columns, sample of dataset is as follows: 1 105 1 104 2 1100 10 1165 813 1320 15 105 19 90 105 813 i want to create a graph to find distance between each node from other. For example if i enter input node 1, it will show that distance between 1 and 105 is 1, and between 1 and 813 is 2 (because it will come next to 105). and between 1 and 1320 is 3. (as shown in image below). and similarly for other nodes. <</matlabcentral/answers/uploaded_files/79512/New%20Bitmap%20Image.bmp>> Any help will be greatly appreciated. Tha saliem https://nl.mathworks.com/matlabcentral/profile/authors/9961300 tag:nl.mathworks.com,2005:Question/650778 2020-11-17T13:02:23Z 2021-01-24T05:33:10Z Generate random number from custom PDF and CDF I basically have the following CDF and PDF respectivley: Where the range is from 0 to as mentioned in the CDF line. I would like to generate random numbers on matlab based on these equations. Has anyone done this before? Anyone has experience on this? I've tried looking on the forum but Thanks in advance!! (For those of you interested, it is the distribution of a 1-D Random Waypoint Mobility model proposed by Bettstetter et al.) Ismael Ouass https://nl.mathworks.com/matlabcentral/profile/authors/13735838 tag:nl.mathworks.com,2005:Question/725277 2021-01-24T00:57:53Z 2021-01-24T04:39:30Z Fast code to open and write separate 366 .bin files for each (row,col) I am trying to speed up my code. I have a 18000*36000*366 matrix. I split the matrix into 18 bands of each 1000* 36000 .bin files located in 366 folders. I plan to run the same code for 18 times. The problem is it takes 3.5hrs to process 1*36000 like I wanted. It is super slow, any help is appreciated. Below is my code, for lat = 1:length(lat_band) % length of lat_band = 1000 for lon = 1:36000 if (mask(lat,lon)~=9) % if ocean then skip data_1km = data; % matrix of size [366,1]; else data_1km = NaN(366,1); end tmp = 'path'; tic for day = 1:366 fwrite(fopen(sprintf('%s%d', tmp, day, '/band_1.bin'), 'a'), data_1km(day),'double'); end fclose('all'); clear data_1km day toc end end nlm https://nl.mathworks.com/matlabcentral/profile/authors/2744890 tag:nl.mathworks.com,2005:Question/725177 2021-01-23T19:53:43Z 2021-01-24T04:15:31Z Excluding folders from a dir Structure I was wondering about excluding folders from a dir struct that contain the words 'output' I understand how to exclude the first couple of entries in the struct d = dir(pathName); d = d(~ismember({d.name},{'.','..'})); but is there a way that I could maybe use regexpi() inorder to find folders that contain the key world then insert them into the second line above? Boris Kabistan https://nl.mathworks.com/matlabcentral/profile/authors/11423895 tag:nl.mathworks.com,2005:Question/723648 2021-01-22T02:44:05Z 2021-01-24T04:07:36Z Hello everyone. I have a long-standing problem, how to calculate the similarity between the two curves that have been fitted. Thank you for your enthusiastic answers. corrcoef(f1,f2) corr2(f1,f2) Wesley https://nl.mathworks.com/matlabcentral/profile/authors/19428999 tag:nl.mathworks.com,2005:Question/725037 2021-01-23T16:47:45Z 2021-01-24T04:04:19Z how to convert dicom image to png Hi all, i want to convert my dicom image to png image. below my coding, but error. Anyone can help me? [I, map]=dicomread('lung.dcm'); imwrite(I,map,'lung.png','png'); ERRORR!!!! Error using imwrite>parse_inputs (line 628) The colormap should have three columns. Error in imwrite (line 440) [data, map, filename, format, paramPairs] = parse_inputs(varargin{:}); CAN HELP ME? mohd akmal masud https://nl.mathworks.com/matlabcentral/profile/authors/10957567 tag:nl.mathworks.com,2005:Question/725342 2021-01-24T03:48:53Z 2021-01-24T03:57:15Z WGAN-GP loss function How to use the wgan-gp loss function？ is it implemenetd in Matlab2020b? daokun lee https://nl.mathworks.com/matlabcentral/profile/authors/8508239 tag:nl.mathworks.com,2005:Question/725347 2021-01-24T03:54:19Z 2021-01-24T03:54:19Z How gpuArray save sparse matrix when running Preconditioned conjugated gradient? Hi, I am using cuda in Matlab to accelerate the Preconditioned conjugated gradient evaluation of "Ax = b". I'm glad to find the pcg without any preconditioner on GPU run faster (x6~7) than ichol preconditioned pcg on CPU. I would like to know how gpuArray allocate the sparse matrix on GPU, in CSR, ELL or any other format. I heard that the different storage format influences the evaluation speed. So I would like to compare these formats on my matrix to optimal my code. I found no option of these formats' setting in the function of gpuArray. I uncertainly speculate gpuArray may allocate the sparse matrix dynamically. Could you give some suggestion or document link of this problem? Thank you. wei zhang https://nl.mathworks.com/matlabcentral/profile/authors/3994770 tag:nl.mathworks.com,2005:Question/725307 2021-01-24T02:19:05Z 2021-01-24T03:53:07Z integral2 error message Error using integral2 (line 71) XMIN must be a floating point scalar. Create the anonymous function. fun = @(x,y) 4+(y./25)-(x.^2)./50; Integrate and to q1, Integrate and to q2 q1 = integral2(fun,-1,1,-1,0) xmin = @(y) -sqrt(1-y.^2); xmax = @(y) sqrt(1-y.^2); q2 = integral2(fun,xmin,xmax,0,1) Error using integral2 (line 71) XMIN must be a floating point scalar. final =q1+q2 anyone can help in this error? Guan We Tan https://nl.mathworks.com/matlabcentral/profile/authors/21189901 tag:nl.mathworks.com,2005:Question/725337 2021-01-24T03:42:36Z 2021-01-24T03:46:48Z 4-PSK modulation code issue I have a project where I have to modify a code to work as a 4-PSK modulation. The part in the function where I have to calculate the correlation is confusing me and I am not sure how am I supoosed to compare 5 correlation matrices in the function code. Edit: I figured that I will use dot function to achieve the correlation matrix but I am still confused about why do I have to use or how am I supposed the 5th correlation matrix or to even calculate it. If it is 4 then it is easy to do but 5 doesn't make sense to me. The picture has the steps of the project; and I have been given a code where I have to modify it from Binary PAM to 4-PSK or 4-Ary Phase Modulation %Binary PAM N = 100; % packet length each packet contains 100 bits N_0 = 1; % noise variance is set to 1 no_of_packets = 1000; % we simulate 1000 packets, where each packet contains N_bits Max_Eb = 8; %in dB units i.e. 10 log (Eb/N_0) where N_0=1 bit_error_rate = zeros(1 ,Max_Eb); %simulated bit error probabilities are stored in this vector for i =1:Max_Eb Eb(i) = 10^(i /10); %for 1-Max_Eb range increment Eb in 1 dB steps end for i =1:Max_Eb %make simulation for Eb values in 1 dB increments total_error_count = 0; %total error count for each Eb for j =1: no_of_packets error_count = Mod_Demod(N,Eb(i),N_0); %error count for each packet total_error_count = total_error_count + error_count; %increment the total error count end bit_error_rate(i) = total_error_count/(N * no_of_packets); %calculate the bit error rate end clf; %clear existing figure semilogy(10*log10(Eb), bit_error_rate, 'r*'); %plot bit error rate vs Eb/N_o in semilog scale grid on; ylabel ('Bit Error Probability'); xlabel ('Eb/N_o in dB'); hold on; semilogy (10*log10(Eb),qfunc( sqrt(2*Eb/N_0))) ; %plot the the or ethical value of error probability of binary PAM legend('simulation','theory'); %%========================================================= % Mod_Demod Function function [error_count] = Mod_Demod(N,E_b,N_0) error_count = 0; % set error count to zero s = zeros (N,1); % transmitted signal vector n = zeros (N,1); % noise vector r = zeros (N,1); % received signal vector C = zeros (N,2); % correlation metric x =round(rand(N,1)); % randomly generated binary data vector x_hat = zeros(N,1); % decoded binary data for i =1:N if x(i) == 0 s(i) = sqrt(E_b); % map 0 -> to s1 = sqrt(E_b) else s(i) = -sqrt(E_b); % map 1 -> to s2 = -sqrt(E_b ) end end n=sqrt (N_0/2)*randn(N,1) ; %generate gaussian noise with variance N_0/2 r = s + n ; %generate the received vector r = s + n C(1:N,1) = r * sqrt(E_b); %% C(r,s1) , correlation of r with s1 C(1:N,2) = r * -sqrt(E_b); %% C(r,s1) , correlation of r with s2 for i =1:N if C(i,1) > C(i,2) % decide on s1 if C(r,s1) > C(r,s2) x_hat(i) = 0; else %% decide on s2 if C(r,s1) < C(r,s2) x_hat(i) = 1; end end for i =1:N if x(i) ~= x_hat(i) %compare original binary data with deduced binary data and find bit errors error_count = error_count + 1; end end end what is confusing me about this is the function, I have already modified my function for S to have 4 binary numbers, function [error_count] = Mod_Demod_two(N,E_b,N_0) error_count = 0; % set error count to zero s = zeros(N/2,2); % transmitted signal vector n = zeros(N,2); % noise vector r = zeros(N,2); % received signal vector C = zeros(N,5); % correlation metric x =round(rand(N,2)); % randomly generated binary data vector x_hat = zeros(N,2); % decoded binary data for i = 1:N/2 if x(i,1)==0 && x(i,2)==0 s(i,1) = sqrt(E_b); s(i,2) = 0; elseif x(i,1)==0 && x(i,2)==1 s(i,1) = 0; s(i,2) = sqrt(E_b); elseif x(i,1)==1 && x(i,2)==0 s(i,1) = -sqrt(E_b); s(i,2) = 0; else s(i,1) = 0; s(i,2) = -sqrt(E_b); end end %================================ This is where I have modified so far================ n=sqrt(N_0/2)*randn(N/2,2); %generate gaussian noise with variance N_0/2 r = s + n; %generate the received vector r = s + n C(1:5,2) = r * sqrt(E_b); %% C(r,s1) , correlation of r with s1 C(1:5,2) = r * -sqrt(E_b); %% C(r,s1) , correlation of r with s2 for i =1:N if C(i,1) > C(i,2) % decide on s1 if C(r,s1) > C(r,s2) x_hat(i) = 0; else %% decide on s2 if C(r,s1) < C(r,s2) x_hat(i) = 1; end end for i =1:N if x(i) ~= x_hat(i) %compare original binary data with dedoced binary data and find bit errors error_count = error_count + 1; end end end The part that is confusing me is the correlation part. I have to compare 5 different correlation matrices to find which one is bigger but I found a code where it compares only 4 and I have no idea what's the point of the 5th correlation matrix This is the part where I am confused about; n=sqrt(N_0/2)*randn(N/2,2); %generate gaussian noise with variance N_0/2 r = s + n; %generate the received vector r = s + n C(1:5,2) = r * sqrt(E_b); %% C(r,s1) , correlation of r with s1 C(1:5,2) = r * -sqrt(E_b); %% C(r,s1) , correlation of r with s2 for i =1:N if C(i,1) > C(i,2) % decide on s1 if C(r,s1) > C(r,s2) x_hat(i) = 0; else %% decide on s2 if C(r,s1) < C(r,s2) x_hat(i) = 1; end end The code that I found compares 4 correlation or does the decision for C matrices function[pb,ps]=cm_sm32(snr_in_dB) N=10000; E=1; snr=10^(snr_in_dB/10); sgma=sqrt(E/snr)/2; s00=[1 0]; s01=[0 1]; s11=[-1 0]; s10=[0 -1]; for i=1:N, temp=rand; if(temp<0.25), dsource1(i)=0; dsource2(i)=0; elseif(temp<0.5), dsource1(i)=0; dsource2(i)=1; elseif(temp<0.75), dsource1(i)=1; dsource2(i)=0; else dsource1(i)=1; dsource2(i)=1; end; end; numofsymbolerror=0; numofbiterror=0; %===================================From Here this is what I want to implement================ for i=1:N, n(1)=gngauss(sgma); n(2)=gngauss(sgma); if((dsource1(i)==0) & (dsource2(i)==0)), r=s00+n; elseif((dsource1(i)==0) & (dsource2(i)==1)), r=s01+n; elseif((dsource1(i)==1) & (dsource2(i)==0)), r=s10+n; else r=s11+n; end; c00=dot(r , s00); c01=dot(r , s01); c10=dot(r , s10); c11=dot(r , s11); c_max=max([c00 c01 c10 c11]); if(c00==c_max) decis1=0;decis2=0; elseif(c01==c_max) decis1=0;decis2=1; elseif(c10==c_max) decis1=1;decis2=0; else decis1=1;decis2=1; end; symbolerror=0; if(decis1~=dsource1(i)), numofbiterror=numofbiterror+1; symbolerror=1; end; if(decis2~=dsource2(i)), numofbiterror=numofbiterror+1; symbolerror=1; end; if(symbolerror==1), numofsymbolerror=numofsymbolerror+1; end; end; ps=numofsymbolerror/N; pb=numofbiterror/(2*N); Khalid Sherif https://nl.mathworks.com/matlabcentral/profile/authors/13786792 tag:nl.mathworks.com,2005:Question/338822 2017-05-05T04:55:30Z 2021-01-24T03:33:53Z rename files using matlab Hello all, I have a folder on my desktop that has 10 text files as following: A.txt Abgd.txt B.txt Bbgd.txt C.txt Cbgd.txt S.txt Sbgd.txt std.txt stdbgd.txt I want to write a code that the changes the names of the first 8 files. I want to rename these files and add an underline (i.e. '_') after the first letterof each file. So my output should look like this: A_.txt A_bgd.txt B_.txt B_bgd.txt C_.txt C_bgd.txt S_.txt S_bgd.txt Here is what I have done so far: clear all; clc; d = 'C:\Users\krraz\Desktop\Day13\*.txt'; oldnames = dir(d); oldnames = {oldnames(~[oldnames.isdir]).name}; L = length(oldnames); oldnames = oldnames(1:L-2); points = oldnames(1:2:end); points = cellfun(@(x) x(1:1), points, 'UniformOutput', false); strr = '_.txt'; strr = string(strr); for n = 1:numel(points) formatSpec = '%1$s%2$s'; points{n} = sprintf(formatSpec,points{n},strr); end bgds = oldnames(2:2:end); bgds = cellfun(@(x) x(1:1), bgds, 'UniformOutput', false); strr = '_bgd.txt'; strr = string(strr); for n = 1:numel(bgds) formatSpec = '%1$s%2$s'; bgds{n} = sprintf(formatSpec,bgds{n},strr); end newnames = [points bgds]; newnames = sort(newnames); for j=1:numel(oldnames) movefile(d,newnames{j},'f'); end But when I run my code, It generates a new folder on my desktop and doesn't change the names of the files. What am I doing wrong? Any insight will be appreciated. Changoleon https://nl.mathworks.com/matlabcentral/profile/authors/8600638 tag:nl.mathworks.com,2005:Question/725322 2021-01-24T02:43:49Z 2021-01-24T03:24:42Z Matrix dimensions must agree. t = [0:0.1:10] L1 = linspace(4,5,101) L2 = linspace(6,7,101) ft1 = 1 - 2*t.^2 ft2 = 3*t - 2*t.^3 t1 = (L1.*y-diff(diff(ft1)))/(2*diff(ft1)) t2 = (L2.*y-diff(diff(ft2)))/(2*diff(ft2)) I dont understand what Im doing wrong here. t, L1, L2, ft1 and ft2 are all 1x101 doubles but i keep getting back matrix dimentions must agree. Im sure the problem has something to do with the fact that im using vectors and the MatLab wants matracies, but im not sure. If anyone knows what im donig wrong to get please let me know. Thank you! Joshua Wille https://nl.mathworks.com/matlabcentral/profile/authors/20775666 tag:nl.mathworks.com,2005:Question/725332 2021-01-24T03:22:49Z 2021-01-24T03:22:49Z how to plot the motor chamber pressure and the vacuum thrust as a function of both time and web assuming quasi-steady state (equilibrium) I have computed the equilibrium pressure assuming a quasi steady state condition: using the following eq attached to this question and below is my code. How do I plot Pc_eq as a function of time? clear all %% Step 1 % ========================================================================= % % Basing on the motor and propellant data indicated in Table 1 and on the % burning surface evolution shown in Figs. 5 and 6 and assuming a constant % chambre temperature profile compute the following curves without taking % into account the non-ideal parameters. %% Step 1.1 %Find: The motor chamber pressure and the vaccume thrust as a % function of both time and web assuming quasi-steady state (equilibrium) % User inputs - First stage P80 SRM % ========================================================================= % mp = 88000; % Propellant Mass [kg] ms = 7330; % Structural mass [kg] l = 10.6; % length [m] d = 3.0; % Diameter [m] f = 3015; % Max thrust(vaccum) [kN] bt = 110; % Buring time [sec] isp = 280; % Specifi Impulse (vaccuum) [sec] % User inputs - Propellant Ballistic Properties % ========================================================================= % a = 1.847e-05; % Temperature coefficient @ 300 K [m/s * Pae-0.4] n = 0.4; % Combustion index tau = 0.0015; % Temperature sensitivity [k^-1] rho = 1790; % Density [kg/m^3] % User inputs - Propellant thermochemocal properties % ========================================================================= % T_F = 3550; % Flame temperature [K] M = 29; % Molecular mass [kg/kmole] gamma = 1.13; % Specific heat ratio % User inputs - Motor geometrical properties % ========================================================================= % d_throat = 0.496; % Throat diameter [m] e = 16; % expansion ratio v_c = 8.6; % Initial chamber volume [m^3] v_frac = 0.85; % volumetric loading fraction (V_c/(V_c+V_p) % constants % ========================================================================= % r = 8314.5 % gas constant [J/kmol) % Calculations % Find: The motor chamber pressure and the vaccum thrust as a % ========================================================================= % a_t = pi* (d_throat/2)^2; % Thrat area [m^2] m_dot = mp/bt; % mass flow rate [kg/s] s_b = 48; % burning surface area - pulled from the Sb vs Y plot [m^2] cap_gamma = sqrt (gamma * (2/(gamma + 1))^((gamma+1)/(gamma-1))); % capital gamma c_star = (1/cap_gamma)*sqrt((r*T_F)/M); K = s_b/a_t; % Klemmung Pc_eq = (a *rho*c_star*K)^(1/(1-n)); Christina Reid https://nl.mathworks.com/matlabcentral/profile/authors/16668139 tag:nl.mathworks.com,2005:Question/724683 2021-01-23T02:52:53Z 2021-01-24T03:19:52Z Fast Fourier Transform Zero Padding Hi all, I am using the code shown below to plot the FFT of some data. My issue is that the "resolution" seems poor, as the x axis is in increments of 0.2. I would like much finer plotting of points, and have recently seen the Zero Padding method. However, everytime I try to implement other solutions on MATLAB answers, I cannot seem to increase the resolution. Could anyone help me with the necessary code for my specific case? O2_exp = [0.0247 0.2372 1.9171 1.5570 0.8016 0.5572 1.2185 1.3601 1.0067 0.7767 1.0244 1.1619 1.0210 0.8791 0.9595 1.0592 1.0274 0.9507 0.9735 1.0303 1.0286 0.9912 0.9924 1.0137 1.0143 0.9982 0.9996 1.0097 1.0174 1.0062 1.0052 1.0115 1.0177 1.0131 1.0150 1.0117 1.0182 1.0153 1.0206 1.0177 1.0243 1.0200 1.0221 1.0207 1.0235 1.0256 1.0275 1.0237 1.0248 1.0264]; figure Fs = 1; L = length(O2_exp); Y = fft(O2_exp); P2 = abs(Y/L); P1 = P2(1:L/2+1); P1(2:end-1) = 2*P1(2:end-1); f = Fs*(0:(L/2))/L; plot(f(2:end),P1(2:end)/max(P1(2:end)),'color','red','linewidth',4) kyle mani https://nl.mathworks.com/matlabcentral/profile/authors/12990070 tag:nl.mathworks.com,2005:Question/725312 2021-01-24T02:36:03Z 2021-01-24T03:15:19Z Invalid expression in function loading file Hi I've written this function function [RTxdone] = ReactionTime('resultsfile';sesid) load 'resultsfile' Rxtcell = ses(sesid)_results(5:800,6); RTa = cell2mat(Rxtcell); for n = 1:225 X = RTa(n:n+8); Y = [0;0;0;0;0;0;0;0;0]; if X==Y RTa(n) = NaN end end RT = RTa(RTa~=0) end Which when I try to call gives this error: Error: File: ReactionTime.m Line: 1 Column: 35 Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses. Not sure what I've done here Owen Gray https://nl.mathworks.com/matlabcentral/profile/authors/20383725 tag:nl.mathworks.com,2005:Question/724932 2021-01-23T13:34:44Z 2021-01-24T03:07:46Z The first function is performing the calculations but the second, when ran, won't graph the results I'm calling these two functions one after another from a menu created using switch (choice), the first one runs fine as I can see the reults come out but the second does not plot the results of the first. function [x, v, t] = performcalcs(m, s1, ~, ~, t0, dt, t_total, ~, v, x, g) i=1; for t = t0: dt: t_total F = - s1 .* x(i) - m .* g; a = F ./ m; v(i+1) = a .* dt + v(i); x(i+1) = x(i) + v(i+1) .* dt; i = i + 1; end end function plotpos(t,x) plot(t,x,'-'); title('Vertical position of mass'); xlabel('t[s]'); ylabel('x[m]'); end Gabriel Earle https://nl.mathworks.com/matlabcentral/profile/authors/21022551 tag:nl.mathworks.com,2005:Question/288885 2016-06-09T14:44:13Z 2021-01-24T03:07:06Z Cause for Matlab error: File on disk might be empty or incomplete. Hi, I get this error seemingly randomly when saving a file: File on disk might be empty or incomplete. Ensure there is sufficient free space on your drive and then save the file again. Do not reload the file before you successfully save it. There is only an "OK" button. When I click "OK" another dialog box comes up stating: &nbsp<filename> This file has been modified outside the Matlab editor. Do you want to reload? The two choices are "yes" and "no". Clicking "No" it seems just returns me to the filename with no file save. When I click "yes" it appears that the file is reloaded as the Matlab editor scrolls to the end of the file. However, when I run that filename with the code changes, even though the editor shows the changes, the filename is run without those code changes. Also, I check the filename using Notepad, and the code changes were actually saved. I have to exit and restart in order to continue. I am running Windows 7 Enterprise, 64 bit with plenty of hard disk space. Thank you Omar https://nl.mathworks.com/matlabcentral/profile/authors/52808 tag:nl.mathworks.com,2005:Question/725317 2021-01-24T02:38:39Z 2021-01-24T02:38:39Z Plotting dipole field given in polar coordinates Hello, I'm trying to plot a dipole field around a uniformly polarized sphere. Here is the setup where u is supposed to represent the field component in r-hat direction and v represents the vector component in theta-hat direction. [x,y] = meshgrid(-8:0.5:8,-8:0.5:8); %% for base change r = sqrt(x.^2 + y.^2); % r in function of (x, y) theta = atan2(y, x); % theta in function of (x, y) %% Constants rad = 2; %radius of sphere pre = 0.1; %pre factor scale1=50; %scaling factors for better visibility scale2=200; %% Definition of vectors in polar coordinates: u = ((2*pre)./(r.*r.*r)).*cos(theta); %r-hat v = (pre./(r.*r.*r)).*sin(theta); %theta-hat afterwards i go over to plotting the vectors using the quiver function. I'm not really sure if u*cos(theta) and v*sin(theta) are the right steps here. Basically, I want to plot the vector field given in polar coordinates in cartesian coordinates and I don't know if my transformation steps are correct. %% plotter figure(1) hold on; for i=1:33 for n=1:33 if((sqrt(x(i,n)*x(i,n)+y(i,n)*y(i,n)))>rad*2) quiver(x(i,n), y(i,n), u(i,n)*cos(theta(i,n)), v(i,n)*sin(theta(i,n)),scale2,'r') hold on; elseif ((sqrt(x(i,n)*x(i,n)+y(i,n)*y(i,n)))>rad) quiver(x(i,n), y(i,n), u(i,n)*cos(theta(i,n)), v(i,n)*sin(theta(i,n)),scale1,'r') hold on; end end end I'm fairly new to matlab so your help is greatly appreciated. Thank You :) Philipp Traxler https://nl.mathworks.com/matlabcentral/profile/authors/16698957 tag:nl.mathworks.com,2005:Question/725047 2021-01-23T16:56:28Z 2021-01-24T02:33:54Z bisector method help and inputs Hello, I'd like some help with my bissector method as it displays an error message each time I run it. Error using APFunction Too many input arguments. Error in test2 (line 12) [deflectionL,tL]= APFunction (PForceL,c,k,LoadingDurationL,tstep); clc;clear; c=800; k=5000000; xL=0; xU= 10; Diff=1; tstep=0.01; while Diff > 0.01 xM = (xU-xL)/2; [PForceL,LoadingDurationL] = myfunction(xL); [PForceU,LoadingDurationU] = myfunction(xU); [PForceM,LoadingDurationM] = myfunction(xM); [deflectionL,tL]= APFunction (PForceL,c,k,LoadingDurationL,tstep); [deflectionU,tU]= APFunction (PForceU,c,k,LoadingDurationU,tstep); [deflectionM,tM]= APFunction (PForceM,c,k,LoadingDurationM,tstep); MaxdL= max(deflectionL); MaxdU= max(deflectionU); MaxdM= max(deflectionM); if MaxdM >0.1 xL=xM; else xU=xM; end Diff = abs(MaxdM-0.1); end henry Jok https://nl.mathworks.com/matlabcentral/profile/authors/21180735 tag:nl.mathworks.com,2005:Question/725242 2021-01-23T22:53:50Z 2021-01-24T02:19:30Z Missing toolbox Parallel computing why am i missing the parallel computing toolbox and the curve fitting toolbox. I recently downloaded R2020b update and these two are missing. JAY CAMERON https://nl.mathworks.com/matlabcentral/profile/authors/6805609 tag:nl.mathworks.com,2005:Question/724318 2021-01-22T16:37:31Z 2021-01-24T02:17:09Z using fwrite for multiple data type at once I am trying to write a vector of data of various data types (all numeric) to a .binary file all at once instead of having to loop through the data set. I have a vector that contains the numbers: myData = [1 3.5 400 75 2.5 6 1]; and then each number has an associated data type: myDataType = {'single','double','single','single','double','single','single'}; Is there a way to use the fwrite function to write all the data of varying types at once? Such as: fwrite(fid,myData,myDataType) This command doesnt work as fwrite. know that for this example that i am giving it would be just as fast to loop through the data and write them to the file one at a time using: for n = 1:length(myData) fwrite(fid,nyData(n),myDataType{n}) end however the data vector i am writing contains thousands of different data and the format of the data type does not follow any particular set pattern and changes. typically, when all the data is the same such as a vector containing 10,000 double values, it is expoenntially faster to write all of the data at once like this: fwrite(fid,myData,'double') than it is to use a for loop. But for my specific case, the data types change. Any help would be greatly appreciated. Eric Alexander https://nl.mathworks.com/matlabcentral/profile/authors/16589662 tag:nl.mathworks.com,2005:Question/725282 2021-01-24T01:01:47Z 2021-01-24T02:07:07Z Is it possible to tell what matlab is "Busy" with? Hi, Maybe a silly question, but it's just out of curiosity. When matlab is stuck at "Busy" or is taking a really long time to execute a command, is it at all possible to see what it's doing live? Or if not, find out what part of the command it is/was stuck on? Thanks in advance David Mabwa https://nl.mathworks.com/matlabcentral/profile/authors/15255963 tag:nl.mathworks.com,2005:Question/725207 2021-01-23T21:01:12Z 2021-01-24T01:48:13Z fly fishing rod simulation Hi. I am an italian fly fishing rodbuilder and I would like to understand how to simulate a bamboo rod physics with classic mechanics math. Known parameters are: shape (basicly hexagonal, six bamboo stripes glued with epoxy, but the rod could be penta or quad), distance of two opposite faces at every N inches or Cm, density, MOE (modulus of elasticity), variation of MOE at different depths from rod surface, rod's components, their weights and their position along or outside the rod itself (top ring, guides, line inside and outside the rod etc etc). the simulation system should include a support where to fix the rod that can move it in various ways: for example the rod is vertical and the handle is traslated vertically back and forth (1 to 2 feet) with an arbitrary frequency. the final scope of the project is to provide an interface to modify parameters in metric or Imperial measure system (rod taper i.e. the dimensions of the rod for its whole length, or stresses in a particular zone of the rod), and obtain back graphs of stress/strain, 3d simulation of rod movements due to traslation, structural limits of the system (alarms in case of maximum strain reached). the simulation can be surely more complex respect all above explanations... but is intended that I don't want someone to resolve the simulation and give me the final result, I am "only" looking for suggestions about what Matlab modules/products could fit better to my project to acquire them and start learning how to use them. thanks in advance Michele michele montessoro https://nl.mathworks.com/matlabcentral/profile/authors/21182962 tag:nl.mathworks.com,2005:Question/724738 2021-01-23T07:39:50Z 2021-01-24T01:43:40Z Subtracting XYZ coordinates defined by matrices I have two matrices, A (96100x3) and B(16416x3). I need to subtract the XYZ coordinates defined by the columns of B from those of A. But as they are of different resolutions, the difference or setxor is still giving sort of union of these two matrices. Is there any way I can subtract the region bounded by B from A? TIA Isaac John https://nl.mathworks.com/matlabcentral/profile/authors/21022777 tag:nl.mathworks.com,2005:Question/724563 2021-01-22T21:54:08Z 2021-01-24T01:17:18Z Replacing empty cells using for loop Hi there, I have 796x1 cell array consisting of 1x1 scalar arrays, or empty arrays. E.g. >> ses1_results = {1.192;0;0;0;0.5678;0;0;0;0;0;0;1;[];1} ses1_results = 14×1 cell array {[ 1.1920]} {[ 0]} {[ 0]} {[ 0]} {[ 0.5678]} {[ 0]} {[ 0]} {[ 0]} {[ 0]} {[ 0]} {[ 0]} {[ 1]} {0×0 double} {[ 1]} The spacing of the 0s is irregular I need to remove all the cells with 0, whilst maintaining the 0x0 cells and the values>0, and then convert that into an array. How can I do this? I've spent a few hours trying to do it like this but can't seem to figure it out: Rxtcell = ses1_results(5:800,6); for n = 1:796 Z = [] Q = 0 x = Rxtcell(n) if 1 == strcmp(x,Q) Rxtcell{n}=; elseif 1== strcmp(x,Z) Rxtcell(n)= ; else end end RxTa = cell2mat(Rxtcell) Owen Gray https://nl.mathworks.com/matlabcentral/profile/authors/20383725 tag:nl.mathworks.com,2005:Question/725292 2021-01-24T01:04:55Z 2021-01-24T01:16:41Z Function as an integrator Hi everybody, I'm computing a numerical solution by Euler's method for a second order differential equation, I have defined the function for the differential equation but I also need to define an additional one as an integrator (like ode45), but by Euler's method. I've tried some computations and agorithms but it does not work. Please, could you help me? This is my code: % Sampling interval h = 0.1; %h = 0.05; %h = 0.01; t0 = 0; % Initial time tf = 4; % Final time t = [t0:h:tf]; % Time vector % Initial value problem th0 = pi/40; % theta(t0) om0 = 0; % ommega(t0) yu = [th0 om0]; e = euler(@yprime,t,h,yu); % Want to call euler's function as an integrator but does not work and has an issue with * multiplication function [yp] = yprime(t,y) L = 0.61; G = 9.81; yp = zeros(2,1); yp(1) = y(2); % Angle theta [rad] yp(2) = (-G/L)*sin(y(1)); % Angular velocity omega [rad/s] end % and my Euler's function as a script: function eu = euler(yp,t,h,y) % Function that computes the values of the angle theta followinf the Euler % method eul = y + yp*h; eu = eul; Hugo Hernández Hernández https://nl.mathworks.com/matlabcentral/profile/authors/19945880 tag:nl.mathworks.com,2005:Question/725297 2021-01-24T01:13:59Z 2021-01-24T01:13:59Z variable displacement Hydraulic motor hello guys do anyone know how to control the displacement of a (variable displacement hydrualic motor) in simulink. I cant find any exemple that describe how to control the motor displacement. I want to control the motor displacement via a solenoid valve. Any tips will help Thanks Omari Diallo https://nl.mathworks.com/matlabcentral/profile/authors/11360816 tag:nl.mathworks.com,2005:Question/93297 2010-01-27T23:56:00Z 2021-01-24T00:51:43Z Why does the MathWorks installer fail to start on Windows? I am trying to install MATLAB on a Windows computer, but the installer will not run. MathWorks Support Team https://nl.mathworks.com/matlabcentral/profile/authors/4622813 tag:nl.mathworks.com,2005:Question/725252 2021-01-23T23:20:04Z 2021-01-24T00:49:57Z Print first few lines of output Suppose I do summary(T) Then it will print out statistics of all the variables in the table, which is good. But at the same time it will output all the information and will create "auto-scroll" that is very cumbersome. Thus I want to print out the first five lines of the output. head(summary(T),5) does not work. alpedhuez https://nl.mathworks.com/matlabcentral/profile/authors/10930090 tag:nl.mathworks.com,2005:Question/725112 2021-01-23T18:11:31Z 2021-01-24T00:45:45Z nested loops for 2 different variables This is the code I am trying to run, and I am unsure what is wrong with my nested loops. Context: I am trying to the find the different values of c and l and calculate the associated costs Cc and Cl for both values . Ultimately I'd like to plot both results to see which combinations of c and l are cheapest. Thank you. clc;clear; a=0; c= 200:10:1200; l= 1:0.5:7; for i=1:length(c) for j=1:length(l) Cc = (10*c)-2000; Cl = 900+825*l.^2-1725*l; a=a+c+l; end end Michael https://nl.mathworks.com/matlabcentral/profile/authors/14342281 tag:nl.mathworks.com,2005:Question/247159 2015-10-06T22:12:41Z 2021-01-24T00:38:33Z How do you run the Activation Client? MATLAB R2015b won't open on my computer. Pop up says my license checkout has failed (License Manager error-9). Where can I find the Activation client to reactivate my license? Molly Smith https://nl.mathworks.com/matlabcentral/profile/authors/7060849 tag:nl.mathworks.com,2005:Question/725247 2021-01-23T23:15:00Z 2021-01-24T00:14:43Z how do i combine two bar graphs I have tried to combine these two graphics in many ways but nothing works for me, just as the creation of the legends gives me an error. I need help for this because neither the combination nor the legends want to serve me, Thank you! b1=bar(app.CasosUIAxes,data1.dateRep,data1.cases); hold on %grafica de barras 2 b2=bar(app.CasosUIAxes,data2.dateRep,data2.cases); hold off legend(app.CasosUIAxes,[b1 b2],'Bar Chart 1','Bar Chart 2') Diego Monsave https://nl.mathworks.com/matlabcentral/profile/authors/12163527