Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9131973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:13:58+00:00 2026-06-17T08:13:58+00:00

I am working with a meteorological dataset and need to extract one column from

  • 0

I am working with a meteorological dataset and need to extract one column from many csv files and compile the results into a new file. I have it working through one month but the script gets stuck when it encounters a shorter month (Subscripted assignment dimension
mismatch). Makes sense, however, I want it to simply keep the NaN values that are originally present in the placeholder matrix D.

Here is the problem part of the script,

%Convert dates to matlab date numbers and get number of rows
Date = datenum(Date{1, 1}, 'dd-mm-yyyy');
T = size(Date, 1);    

%# Preallocate a matrix to hold all the data, and add the date column
D = [Date, NaN(T, NumFile)];

%# Loop over the csv files, get the eleventh column and add it to the data matrix
for k = 1:NumFile
FileList = dir('*.csv');
NumFile = size(FileList,1);
    filename = FileList(k).name;
    disp(filename);
    %# Get the current file name
    CurFilePath = filename;

    %# Open the current file for reading and scan in the second column using numerical format
    fid1 = fopen(CurFilePath, 'r');
    CurData = textscan(fid1, '%*s %*s %*s %*s %*s %*s %*s %*s %f %*[^\n]', 'Delimiter', ',"', 'HeaderLines', 17, 'MultipleDelimsAsOne',true);
    fclose(fid1);

    %Add the current data to the cell array
    D(:, k+1) = CurData{1, 1};
end

So, how can the shorter months be forced to the size of 31 days months to fit the placeholder matrix D.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:13:59+00:00Added an answer on June 17, 2026 at 8:13 am

    When you are assigning D with the colon operator in one dimension, Matlab has to assume that you are assigning all elements in the row. To fix it, simply exchange the colon with a 1:numberOfDaysInMonth.That way Matlab will only assign the number of values you specify and leave the rest unchanged, Nan in this case.

    numberOfDaysInMonth you can calculate as size(CurData{1, 1},1)

    In all, exchange that next-to-last line in your script with:

    %Add the current data to the cell array
    numberOfDaysInMonth = size(CurData{1, 1},1);
    D(1:numberOfDaysInMonth, k+1) = CurData{1, 1};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working in Node I need to convert my request path into a relative path
Working with an api and I need to one of the first responses alongside
Working on game where plates will be falling from top to bottom. Some plates
Working in Backbone.js, I'd like to set a model property from within a method
Working on a new project in Laravel 4 (a.k.a Illuminate) I'm trying to create
Working on some code and I'm given the error when running it from the
Working through more book examples- this one is a partial poker program- This segment
Working with one of our partners, we have developed now two separate sets of
Working with classes in one of my projects for the first time, I seem
Working on an app using Akka 2 deployed with Play-mini. I pulled logback into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.