Answered

Reading different lines with different numbers of data

This code is assuming that the only lines that have 3 fields is your data: file = 'filename.txt'; fileID = fopen(file); data ...

Reading different lines with different numbers of data

This code is assuming that the only lines that have 3 fields is your data: file = 'filename.txt'; fileID = fopen(file); data ...

6 months ago | 2

| accepted

Answered

Combine three or more MATLAB figures

I would save figures then plot them as subplots like this: %First Figure h1 = openfig('test1.fig','reuse'); % open figure ax1...

Combine three or more MATLAB figures

I would save figures then plot them as subplots like this: %First Figure h1 = openfig('test1.fig','reuse'); % open figure ax1...

6 months ago | 1

| accepted

Answered

No. of elements, mean and standard deviation of a field - conditions on other fields

Maybe something like this? f1 = [S.f1]; f2 = [S.f2]; f3 = [S.f3]; f1_cond1 = numel(f1(f1 > 50 & f1(f1 <=100))); f2_idx = ...

No. of elements, mean and standard deviation of a field - conditions on other fields

Maybe something like this? f1 = [S.f1]; f2 = [S.f2]; f3 = [S.f3]; f1_cond1 = numel(f1(f1 > 50 & f1(f1 <=100))); f2_idx = ...

6 months ago | 0

| accepted

Answered

Rearrange an array based on a matrix

Would something like this work: for i = 1:numel(V) [~,k] = find(M == V(i)); col_v = M(:,k); col_v = col_v(col_v ...

Rearrange an array based on a matrix

Would something like this work: for i = 1:numel(V) [~,k] = find(M == V(i)); col_v = M(:,k); col_v = col_v(col_v ...

6 months ago | 0

| accepted

Answered

How save an Array in nc

You need to save your lat, lon, time, and data to nc file. Look at documentaion for nccreate. It should be something like this b...

How save an Array in nc

You need to save your lat, lon, time, and data to nc file. Look at documentaion for nccreate. It should be something like this b...

6 months ago | 0

Answered

Undefined Function or Variable

You are not setting R becuase you have it in a try catch block and it is throwing an error. That is because you are tryind to in...

Undefined Function or Variable

You are not setting R becuase you have it in a try catch block and it is throwing an error. That is because you are tryind to in...

6 months ago | 1

Answered

Using ismember on vector with strings

if you are trying to match string to string, try this: if any(contains([' nafor','kform','acet'],result))

Using ismember on vector with strings

if you are trying to match string to string, try this: if any(contains([' nafor','kform','acet'],result))

6 months ago | 0

| accepted

Answered

Parfor problems about loopVar = initVal:endVal

You are setting the variable xhat in the parfor and using the prevous itereation of xhat. You need to just access and set a slic...

Parfor problems about loopVar = initVal:endVal

You are setting the variable xhat in the parfor and using the prevous itereation of xhat. You need to just access and set a slic...

6 months ago | 0

Answered

How to organize data in matrix

Did you preallocate output array? output_array = nan(60,45,348); for time_idx = 1:348 output_array(:,:,time_idx) = ncread...

How to organize data in matrix

Did you preallocate output array? output_array = nan(60,45,348); for time_idx = 1:348 output_array(:,:,time_idx) = ncread...

6 months ago | 0

Answered

How to download multiple data files at once using matlab

Try this. I also put where you could change year also. year = 2019; start_jd = 182; end_jd = 212; for jd = start_jd:end_jd...

How to download multiple data files at once using matlab

Try this. I also put where you could change year also. year = 2019; start_jd = 182; end_jd = 212; for jd = start_jd:end_jd...

6 months ago | 2

| accepted

Answered

reading of xls file without nan

Use this to get a cell array of mixed data types (doubles and char): [~,~,raw] = xlsread('myFile.xlsx')

reading of xls file without nan

Use this to get a cell array of mixed data types (doubles and char): [~,~,raw] = xlsread('myFile.xlsx')

6 months ago | 0

| accepted

Answered

Picking one line from a .txt file.

Try this: filename = 'file.txt' linenum = 5; fileID = fopen(filename); C = textscan(fileID,'%s',1,'delimiter','\n', 'headerl...

Picking one line from a .txt file.

Try this: filename = 'file.txt' linenum = 5; fileID = fopen(filename); C = textscan(fileID,'%s',1,'delimiter','\n', 'headerl...

6 months ago | 0

| accepted

Answered

Vectorization of a function

I think you have some of your dot operators wrong: d1 = (log(S./K) +(r+(1/2)*sigma^2)*t)/(sigma*sqrt(t)); d2 = d1-sigma*sqrt(t...

Vectorization of a function

I think you have some of your dot operators wrong: d1 = (log(S./K) +(r+(1/2)*sigma^2)*t)/(sigma*sqrt(t)); d2 = d1-sigma*sqrt(t...

6 months ago | 1

Answered

Index in position 2 exceeds array bounds (must not exceed 1)

The variables u_c and u_p are vectors or the size of the second dimension is 1. Then you try to set these variables with i in th...

Index in position 2 exceeds array bounds (must not exceed 1)

The variables u_c and u_p are vectors or the size of the second dimension is 1. Then you try to set these variables with i in th...

6 months ago | 1

Answered

How to load an Excel file that changes with the date?

You could just convert numbers to string and piece it together like this: date = datetime('now'); [y,m,d] = ymd(date); filena...

How to load an Excel file that changes with the date?

You could just convert numbers to string and piece it together like this: date = datetime('now'); [y,m,d] = ymd(date); filena...

6 months ago | 1

| accepted

Answered

saving excel file as a new sheet in another excel file using matlab

This will copy workseet from InputExcel and paste it after last sheet in OutputExcel: InputExcel = 'D:\Answers\input.xlsx'; Ou...

saving excel file as a new sheet in another excel file using matlab

This will copy workseet from InputExcel and paste it after last sheet in OutputExcel: InputExcel = 'D:\Answers\input.xlsx'; Ou...

6 months ago | 0

Answered

Finding the 10 nearest points to every point (with corresponding distances) within a single variable

Try this: load('F_points.mat') f = cell2mat(F_points)'; Mdl = KDTreeSearcher(f); [idx,distance] = knnsearch(Mdl,f,'k',11); ...

Finding the 10 nearest points to every point (with corresponding distances) within a single variable

Try this: load('F_points.mat') f = cell2mat(F_points)'; Mdl = KDTreeSearcher(f); [idx,distance] = knnsearch(Mdl,f,'k',11); ...

6 months ago | 1

Answered

using strcmpi in switch case

For a switch statement try this: function state = stateAbbreviation(inputStr) switch upper(inputStr) case 'ALASKA' ...

using strcmpi in switch case

For a switch statement try this: function state = stateAbbreviation(inputStr) switch upper(inputStr) case 'ALASKA' ...

6 months ago | 1

| accepted

Answered

Question about for loop problem

In the last line, you are summing just the last element. Remove the j index. EUI_total = sum(EUI); I would vectoize this code...

Question about for loop problem

In the last line, you are summing just the last element. Remove the j index. EUI_total = sum(EUI); I would vectoize this code...

7 months ago | 0

| accepted

Question

Remove Bad File from Custom Datastore

I created a custom datastore to read in NetCDF files. I have the datastore check to see if each file has the same parameters as ...

7 months ago | 0 answers | 0

Answered

importdata only gives me 4 digits of accuracy how do I change

I think you still have your accuracy, it is just displaying 4 digits. You can test then by writing a text file with one of your ...

importdata only gives me 4 digits of accuracy how do I change

I think you still have your accuracy, it is just displaying 4 digits. You can test then by writing a text file with one of your ...

7 months ago | 1

| accepted

Answered

Reading Multiple script files containing numbers and text, file format is not any specific format

If you have 2014a then you dont have the datastore function, you should upgrade to a newer version if you can. Otherwise, here i...

Reading Multiple script files containing numbers and text, file format is not any specific format

If you have 2014a then you dont have the datastore function, you should upgrade to a newer version if you can. Otherwise, here i...

7 months ago | 0

| accepted

Answered

Reading Multiple script files containing numbers and text, file format is not any specific format

Have you tried a datastore? folder = 'D:\files'; %this is folder where the data files are ds = datastore(folder); data = read...

Reading Multiple script files containing numbers and text, file format is not any specific format

Have you tried a datastore? folder = 'D:\files'; %this is folder where the data files are ds = datastore(folder); data = read...

7 months ago | 0

Answered

How to read in a non-standard formated CSV file containing times and measurments and change the output format?

This gets the anwer if you drop the fraction and the time format is HHmmss, if you have a fraction you can edit the line with ti...

How to read in a non-standard formated CSV file containing times and measurments and change the output format?

This gets the anwer if you drop the fraction and the time format is HHmmss, if you have a fraction you can edit the line with ti...

8 months ago | 0

| accepted

Solved

Determine whether a vector is monotonically increasing

Return true if the elements of the input vector increase monotonically (i.e. each element is larger than the previous). Return f...

8 months ago

Solved

Swap the first and last columns

Flip the outermost columns of matrix A, so that the first column becomes the last and the last column becomes the first. All oth...

8 months ago

Solved

Create a dictionary

The goal is to write a function that returns a dictionary from a list of words or phrases and their definitions. Here is an exam...

8 months ago

Solved

Triangle Numbers

Triangle numbers are the sums of successive integers. So 6 is a triangle number because 6 = 1 + 2 + 3 which can be displa...

8 months ago

Solved

Find all elements less than 0 or greater than 10 and replace them with NaN

Given an input vector x, find all elements of x less than 0 or greater than 10 and replace them with NaN. Example: Input ...

8 months ago