Answered

I am getting this error "The right and left hand sides must have the same number of elements" while computing g(i)

Try replacing this line: g(i) = abs(real(v_ref - vc_k1)) + abs(imag(v_ref - vc_k1)); with this line: g(:,i) = abs(real(v_ref(...

I am getting this error "The right and left hand sides must have the same number of elements" while computing g(i)

Try replacing this line: g(i) = abs(real(v_ref - vc_k1)) + abs(imag(v_ref - vc_k1)); with this line: g(:,i) = abs(real(v_ref(...

5 days ago | 0

Answered

How to save a value from a slider

One thing to note is that plotButtonPushed() is nested inside changeThreshold(), so the main function buttonPlot() will not see ...

How to save a value from a slider

One thing to note is that plotButtonPushed() is nested inside changeThreshold(), so the main function buttonPlot() will not see ...

5 days ago | 0

Answered

Select lines from table to plot in MATLAB GUI

You can create one line for each spectrum (this would probably be in the plot button Callback) and then set the visibility of th...

Select lines from table to plot in MATLAB GUI

You can create one line for each spectrum (this would probably be in the plot button Callback) and then set the visibility of th...

5 days ago | 0

| accepted

Answered

Save multiple columns of multiple csv files?

[file_list, path_n] = uigetfile('.csv', 'Grab csv', 'Multiselect', 'on'); if ~iscell(file_list) file_list = {file_list}; ...

Save multiple columns of multiple csv files?

[file_list, path_n] = uigetfile('.csv', 'Grab csv', 'Multiselect', 'on'); if ~iscell(file_list) file_list = {file_list}; ...

6 days ago | 0

| accepted

Answered

Setting section = NaN deletes part of matrix

Change this: bath_50m(ilon, ilat) = NaN; to this: bath_50m(ilat, ilon) = NaN; The reason is because this happened: bath_ch...

Setting section = NaN deletes part of matrix

Change this: bath_50m(ilon, ilat) = NaN; to this: bath_50m(ilat, ilon) = NaN; The reason is because this happened: bath_ch...

6 days ago | 0

| accepted

Answered

How to plot overlapped graphs better?

Maybe make top line dotted: figure(3) plot(t,mu_true,"b-"); hold on plot(t,mu_predicted , "r:"); xlabel('t'); ylabel('result...

How to plot overlapped graphs better?

Maybe make top line dotted: figure(3) plot(t,mu_true,"b-"); hold on plot(t,mu_predicted , "r:"); xlabel('t'); ylabel('result...

6 days ago | 0

Answered

Trouble using strings in If statements using OR

if race == "H2" || race == "H1" || race == "H3" || race == "H4"

Trouble using strings in If statements using OR

if race == "H2" || race == "H1" || race == "H3" || race == "H4"

6 days ago | 0

| accepted

Answered

I need to read an array to see if it has repeated elements (using for loop)

You can do it with two for loops like that, but note that if an element occurs more than two times, each pair will be counted, e...

I need to read an array to see if it has repeated elements (using for loop)

You can do it with two for loops like that, but note that if an element occurs more than two times, each pair will be counted, e...

6 days ago | 1

Answered

When a structure is passed to a function, can we add a field to it?

The answer is yes, the function can add a new field and pass the struct back out, and no, you don't have to create a new struct ...

When a structure is passed to a function, can we add a field to it?

The answer is yes, the function can add a new field and pass the struct back out, and no, you don't have to create a new struct ...

6 days ago | 0

| accepted

Answered

read alot of csv files, average certain rows and columns and output in a new file

This will read all the .csv files in a specified directory, do the averaging of non-zero values over those columns and rows, and...

read alot of csv files, average certain rows and columns and output in a new file

This will read all the .csv files in a specified directory, do the averaging of non-zero values over those columns and rows, and...

6 days ago | 1

| accepted

Answered

plot data into a while lopp without storing the data

If you want each new iteration to replace previously plotted results: i = 0 while i < 2500 % do stuff hold off...

plot data into a while lopp without storing the data

If you want each new iteration to replace previously plotted results: i = 0 while i < 2500 % do stuff hold off...

6 days ago | 0

| accepted

Answered

Plotting different variable sets on same graph

plot(Current1, Power1,'r') hold on plot(Current2, Power2,'b')

Plotting different variable sets on same graph

plot(Current1, Power1,'r') hold on plot(Current2, Power2,'b')

6 days ago | 0

| accepted

Answered

A compact way to find elements of an array which are greater, equal, or less than the elements of a second array

a1 = [0 4 7 8 1 2 3]'; a2 = [4 4 6 9 9 1 1]'; b = sign(a1-a2)

A compact way to find elements of an array which are greater, equal, or less than the elements of a second array

a1 = [0 4 7 8 1 2 3]'; a2 = [4 4 6 9 9 1 1]'; b = sign(a1-a2)

6 days ago | 1

| accepted

Answered

How do you set the scale on a color bar from the figure window?

i don't know how to do it from the figure editor tools, but you can do it with a few lines of code, below. To demonstrate, I'll ...

How do you set the scale on a color bar from the figure window?

i don't know how to do it from the figure editor tools, but you can do it with a few lines of code, below. To demonstrate, I'll ...

6 days ago | 0

Answered

if statement for every possibility

n = 10:99; weird_numbers = []; for i = n factors = divisors(i); factorArray = factors(1:end-1); lengt...

if statement for every possibility

n = 10:99; weird_numbers = []; for i = n factors = divisors(i); factorArray = factors(1:end-1); lengt...

6 days ago | 0

| accepted

Answered

Calculate average between min and max numbers in column 3 depending on values in column 2, for each value in column 1

matrix = randi([1 16],2000,3); search_number = 7; idx_1 = matrix(:,1) == search_number; col2_vals = unique(matrix(idx_1...

Calculate average between min and max numbers in column 3 depending on values in column 2, for each value in column 1

matrix = randi([1 16],2000,3); search_number = 7; idx_1 = matrix(:,1) == search_number; col2_vals = unique(matrix(idx_1...

7 days ago | 1

Answered

Find the Minimum Combination of Sum

N = 100; window_size = 3; A = rand(N,1); signs = 1-2*(dec2bin(0:2^(window_size-1)-1,window_size)-'0').'; comb = NaN(N,1)...

Find the Minimum Combination of Sum

N = 100; window_size = 3; A = rand(N,1); signs = 1-2*(dec2bin(0:2^(window_size-1)-1,window_size)-'0').'; comb = NaN(N,1)...

7 days ago | 1

| accepted

Answered

Getting "Index exceeds array bounds" for line 103 but I do not see how the index number is more than the elements. Any help would be awesome!

Assuming output is an n-by-6 cell array, length(output) will be n if n >= 6 and 6 otherwise (i.e., if n < 6). Note that length()...

Getting "Index exceeds array bounds" for line 103 but I do not see how the index number is more than the elements. Any help would be awesome!

Assuming output is an n-by-6 cell array, length(output) will be n if n >= 6 and 6 otherwise (i.e., if n < 6). Note that length()...

7 days ago | 0

Answered

Why won't this function plot?

Try plot(c1_exp) or plot(t,c1_exp) With your for loop, you're plotting one data point at a time, which is imposs...

Why won't this function plot?

Try plot(c1_exp) or plot(t,c1_exp) With your for loop, you're plotting one data point at a time, which is imposs...

7 days ago | 0

Answered

How do I convert a frequency table to a single vector?

First, setting up the variable as you have it: Blank2 = zeros(23,2); Blank2(:,1) = 1:23; Blank2(3,2) = 1; Blank2(4,2) = 8; ...

How do I convert a frequency table to a single vector?

First, setting up the variable as you have it: Blank2 = zeros(23,2); Blank2(:,1) = 1:23; Blank2(3,2) = 1; Blank2(4,2) = 8; ...

8 days ago | 0

| accepted

Answered

Create push buttons with a For loop and provide individual callbacks within the For loop.

When you specify a callback as a character vector, the callback executes in the MATLAB workspace (reference here), which may or ...

Create push buttons with a For loop and provide individual callbacks within the For loop.

When you specify a callback as a character vector, the callback executes in the MATLAB workspace (reference here), which may or ...

8 days ago | 0

| accepted

Answered

Split a vector into 2 oscillating vectors?

Here is a way to do it. Demonstrating with smaller vectors so as to more easily verify the result. To use it on your column vect...

Split a vector into 2 oscillating vectors?

Here is a way to do it. Demonstrating with smaller vectors so as to more easily verify the result. To use it on your column vect...

8 days ago | 0

| accepted

Answered

For Loop Question on index

data = [ ... 1.0 68.0 45.0 92.0; ... 2.0 83.0 54.0 93.0; ... 3.0 61.0 67.0 91.0; ... 4.0 70.0 66....

For Loop Question on index

data = [ ... 1.0 68.0 45.0 92.0; ... 2.0 83.0 54.0 93.0; ... 3.0 61.0 67.0 91.0; ... 4.0 70.0 66....

8 days ago | 0

| accepted

Answered

How can I randomize positions with retract/replacement and save in a text file?

It sounds like you want a 30-by-40 matrix where each element is one of {20,40,60,80,100,120,140} and no two adjacent elements on...

How can I randomize positions with retract/replacement and save in a text file?

It sounds like you want a 30-by-40 matrix where each element is one of {20,40,60,80,100,120,140} and no two adjacent elements on...

8 days ago | 0

| accepted

Answered

How to replace the numbers in matrix?

Here is a way to do it using linear interpolation on each row. It will interpolate between the non-zero numbers to fill in the z...

How to replace the numbers in matrix?

Here is a way to do it using linear interpolation on each row. It will interpolate between the non-zero numbers to fill in the z...

8 days ago | 1

| accepted

Answered

How to display sequence of images in GUI

This line: img_files = num2str((1:seq_len)', [img_path '%04i.jpg']); should be like this: img_files = strcat(img_path,num2str...

How to display sequence of images in GUI

This line: img_files = num2str((1:seq_len)', [img_path '%04i.jpg']); should be like this: img_files = strcat(img_path,num2str...

8 days ago | 0

Answered

I dont understand, i try to use solve to find x in Matlab Function Block

Looks like you should use syms rather than sym fcn(0) function x = fcn(y) syms a; r1=7.3e-5; r2=-1.1e-7; s1=1.6e-1; s2=1....

I dont understand, i try to use solve to find x in Matlab Function Block

Looks like you should use syms rather than sym fcn(0) function x = fcn(y) syms a; r1=7.3e-5; r2=-1.1e-7; s1=1.6e-1; s2=1....

8 days ago | 0

Answered

how to create a matrix when using surf function？

What you are doing there is making F a scalar, but F needs to be a matrix the same size as u and v, so something like this: F =...

how to create a matrix when using surf function？

What you are doing there is making F a scalar, but F needs to be a matrix the same size as u and v, so something like this: F =...

8 days ago | 1

Answered

How to export matrix in the form of (column number, row number, value) in CSV?

A = randn(8,4) [m,n] = size(A); [c,r] = meshgrid(1:n,1:m); writematrix([c(:) r(:) A(:)],'output.csv'); % check the result ...

How to export matrix in the form of (column number, row number, value) in CSV?

A = randn(8,4) [m,n] = size(A); [c,r] = meshgrid(1:n,1:m); writematrix([c(:) r(:) A(:)],'output.csv'); % check the result ...

8 days ago | 0

| accepted