Answered

Getting statistics from a struct

If measurementA is just one value, you can do: mean([myResults.MeasurementA]) Try it for your data and look at the resul...

Getting statistics from a struct

If measurementA is just one value, you can do: mean([myResults.MeasurementA]) Try it for your data and look at the resul...

10 years ago | 1

| accepted

Answered

Draw Legend in MATLAB

For the plot you DO NOT want to show in the legend, do: h = plot(x,y,'-+); %your data set(get(get(h,'Annotation'),'Lege...

Draw Legend in MATLAB

For the plot you DO NOT want to show in the legend, do: h = plot(x,y,'-+); %your data set(get(get(h,'Annotation'),'Lege...

10 years ago | 0

Answered

How to read many arbitrary text files in MATLAB?

k = 1; while exist(['ClCdCm',num2str(k),'.txt'],'file') %insert code to read file k = k + 1; end

How to read many arbitrary text files in MATLAB?

k = 1; while exist(['ClCdCm',num2str(k),'.txt'],'file') %insert code to read file k = k + 1; end

10 years ago | 0

Answered

fprintf not printing correct string

Use: fprintf('%4s %15s \n',str_dat(i,:),num2str(dat(i))) You were not telling matlab to use all the columns of the array...

fprintf not printing correct string

Use: fprintf('%4s %15s \n',str_dat(i,:),num2str(dat(i))) You were not telling matlab to use all the columns of the array...

10 years ago | 0

Answered

Get new variable based on the average of a column - Matlab

See file

Get new variable based on the average of a column - Matlab

See file

10 years ago | 2

| accepted

Answered

Easy textscan question. What is this input?

Yes, 1 is the number of times it repeats the ignore 2 strings, read number instruction. You can use fgetl to read one line at a...

Easy textscan question. What is this input?

Yes, 1 is the number of times it repeats the ignore 2 strings, read number instruction. You can use fgetl to read one line at a...

10 years ago | 0

| accepted

Answered

PushButton HitCounter / simple question

Add handles.counter = 0; in the GUI opening function. Then in the pushbutton, increment the counter handles.counte...

PushButton HitCounter / simple question

Add handles.counter = 0; in the GUI opening function. Then in the pushbutton, increment the counter handles.counte...

10 years ago | 4

| accepted

Answered

Using ODE45 to solve a state space system.

First, the size of the array of initial conditions has to be the same of the number of equations you want to solve. So, in your ...

Using ODE45 to solve a state space system.

First, the size of the array of initial conditions has to be the same of the number of equations you want to solve. So, in your ...

10 years ago | 0

| accepted

Answered

HOW TO WRITE THE FOLLOWING FUNCTION IN A MATLAB PROGRAM ? ALSO TELL THE WAY TO PLOT F(X)

x = linspace(1e-6,2-1e-6,100); f1 = x(x>0&x<1); f2 = x(x>1&x<2)/2+5; plot(x,[f1,f2])

HOW TO WRITE THE FOLLOWING FUNCTION IN A MATLAB PROGRAM ? ALSO TELL THE WAY TO PLOT F(X)

x = linspace(1e-6,2-1e-6,100); f1 = x(x>0&x<1); f2 = x(x>1&x<2)/2+5; plot(x,[f1,f2])

10 years ago | 0

Answered

How to take the average of each column of a matrix without including a certain number

Let's call your array "a": my_mean = zeros(size(a,2),1); for i = 1:size(a,2) d = a(:,i);d = d(d~=0); my_me...

How to take the average of each column of a matrix without including a certain number

Let's call your array "a": my_mean = zeros(size(a,2),1); for i = 1:size(a,2) d = a(:,i);d = d(d~=0); my_me...

10 years ago | 1

Answered

Problem with fsolve for non linear system

Do this: - in your main function, after calculating P1,P2,P3, put: P0 = [P1(i,1); P2(i,1); P3(i,1)]; options = optimo...

Problem with fsolve for non linear system

Do this: - in your main function, after calculating P1,P2,P3, put: P0 = [P1(i,1); P2(i,1); P3(i,1)]; options = optimo...

10 years ago | 1

| accepted

Answered

Multiple logic outputs not working

You need to wrap everything into a loop DTS = false(3,1); for i = 1:numel(month) ...your code end and use month...

Multiple logic outputs not working

You need to wrap everything into a loop DTS = false(3,1); for i = 1:numel(month) ...your code end and use month...

10 years ago | 0

| accepted

Answered

Issue with GUI editbox callback

You need to save your variables (i.e. the strings from the editboxes) as fields of the structure handles. So correct your functi...

Issue with GUI editbox callback

You need to save your variables (i.e. the strings from the editboxes) as fields of the structure handles. So correct your functi...

10 years ago | 0

| accepted

Answered

Importdata does not import whole .txt file

I don't know what is wrong with importdata. This version will work. The size of k was based on your file, it may need to be chan...

Importdata does not import whole .txt file

I don't know what is wrong with importdata. This version will work. The size of k was based on your file, it may need to be chan...

10 years ago | 1

| accepted

Answered

Undefined function t for autonomous ODE

You need to put this part in a separate function and run the new function you create options = odeset('RelTol', 1e-4, '...

Undefined function t for autonomous ODE

You need to put this part in a separate function and run the new function you create options = odeset('RelTol', 1e-4, '...

10 years ago | 1

| accepted

Answered

how to compare special characters in string

If index is empty, $ is not in the string str='$(0)parameter'; index = strfind(str,'$');

how to compare special characters in string

If index is empty, $ is not in the string str='$(0)parameter'; index = strfind(str,'$');

10 years ago | 0

| accepted

Answered

How to have a function have any number of input arguments

function myfunction(varargin) if(nargin == 1) ..code if there is only one input ...e.g., x = varargin{1}; ...

How to have a function have any number of input arguments

function myfunction(varargin) if(nargin == 1) ..code if there is only one input ...e.g., x = varargin{1}; ...

10 years ago | 0

| accepted

Answered

How to find repeated array in a matrix

d = []; for i = 1:numel(b) d = [d;find(a==b(i))]; end

How to find repeated array in a matrix

d = []; for i = 1:numel(b) d = [d;find(a==b(i))]; end

10 years ago | 0

| accepted

Answered

Different outcome by using self time iteration and ode15s.

If you look into your ode, there are a number of variables that you reinitialize any time the function is called, whereas in you...

Different outcome by using self time iteration and ode15s.

If you look into your ode, there are a number of variables that you reinitialize any time the function is called, whereas in you...

10 years ago | 0

| accepted

Answered

How can I write in excel multiple columns as vectors?

You can create dynamically the range to write to. For instance, starting from A1: xlswrite('myfile.xlsx',Y, ['A1:',char(64+...

How can I write in excel multiple columns as vectors?

You can create dynamically the range to write to. For instance, starting from A1: xlswrite('myfile.xlsx',Y, ['A1:',char(64+...

10 years ago | 0

Answered

Removing data points that are out of a specific boundary

[i,~] = find(A(:,1) > 5 & A(:,2) < 4); A(i,:) = []

Removing data points that are out of a specific boundary

[i,~] = find(A(:,1) > 5 & A(:,2) < 4); A(i,:) = []

10 years ago | 1

| accepted

Answered

How do you operate on only the non-zero elements of columns within an array?

For sum: netcfq(netcfq<0) = 0; mysum = sum(netcfq,1) for other functions, you could use a loop on the columns and a t...

How do you operate on only the non-zero elements of columns within an array?

For sum: netcfq(netcfq<0) = 0; mysum = sum(netcfq,1) for other functions, you could use a loop on the columns and a t...

10 years ago | 1

Answered

How to apply conditional statements so as to select certain rows or columns on a given dataset.

clc clearvars % Read file filecontent = cell(1000,1); k = 0; fid = fopen('mydata.txt','r'); while 1 ...

How to apply conditional statements so as to select certain rows or columns on a given dataset.

clc clearvars % Read file filecontent = cell(1000,1); k = 0; fid = fopen('mydata.txt','r'); while 1 ...

10 years ago | 1

Answered

What should be modified inside the for loop?

Change these lines: f_x_loop = (F*x_a)/(s*Q) f_x_loop_save(i) = f_x_loop(i) into: f_x_loop_save(i) = (F*x_a)/(s*...

What should be modified inside the for loop?

Change these lines: f_x_loop = (F*x_a)/(s*Q) f_x_loop_save(i) = f_x_loop(i) into: f_x_loop_save(i) = (F*x_a)/(s*...

10 years ago | 0

| accepted

Answered

Adding cell array elements

If all the cells are consistent: mysum = C{1}; for i = 2:numel(C) mysum = mysum + C{i}; end

Adding cell array elements

If all the cells are consistent: mysum = C{1}; for i = 2:numel(C) mysum = mysum + C{i}; end

10 years ago | 1

| accepted

Answered

for loop and xlswrite

K is not an integer so you can't use it to select the excel cell. Do this: j = 0; for k=1:0.5:5 j = j + 1; ...

for loop and xlswrite

K is not an integer so you can't use it to select the excel cell. Do this: j = 0; for k=1:0.5:5 j = j + 1; ...

10 years ago | 1

| accepted

Answered

I have X vector and Y vector. I have plotted graph. Now I sorted out some peak values (from Y). Stored in pks. Now, corresponding to these peaks values(pks), how I can find its corresponding X values?

If there is a biunivocal correspondence between X and Y (i.e. to each value of X corresponds only one value of Y and vice versa)...

I have X vector and Y vector. I have plotted graph. Now I sorted out some peak values (from Y). Stored in pks. Now, corresponding to these peaks values(pks), how I can find its corresponding X values?

If there is a biunivocal correspondence between X and Y (i.e. to each value of X corresponds only one value of Y and vice versa)...

10 years ago | 0

| accepted

Answered

Assignment between structures with common fields

If you do not want to assign all the fields of A to B, I'd do: f = {'field1','field2'}; % list of fields for i ...

Assignment between structures with common fields

If you do not want to assign all the fields of A to B, I'd do: f = {'field1','field2'}; % list of fields for i ...

10 years ago | 0