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

  • Home
  • SEARCH
  • 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 7795939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:13:00+00:00 2026-06-01T23:13:00+00:00

This is related to the post display all elements in a nested cell array

  • 0

This is related to the post

display all elements in a nested cell array (with character entries)

with a change where entries are characters. A new question was asked for clarity.

Now :

a =

{1x10 cell}    {1x10 cell}    {1x10 cell}    {1x10 cell}

a{:}=

ans = [0]    [0.4000]    [0]    [0]    [0]    [0]    [0]    [0]    [0]    [0]

ans = [0]    [0]    [0.2000]    [0]    [0.2000]    [0]    [0.2000]    [0]    [0]    [0]

ans = [0]    [0]    [0]    [0]    [0]    [0.2000]    [0]    [0]    [0.2000]    [0.2000]

ans = [0]    [0.2000]    [0]    [0]    [0]    [0]    [0]    [0.4000]    [0]    [0.2000]

the answer to the previous was:

fileID = fopen('a.txt', 'at');
fprintf(fileID, '%2.8s \n', cellfun(@(x) char(x), a));
fclose(fileID);

How to solve it now?
want to print:

           0  0.4  0    0  0   0  0   0  0  0
           0  0    0.2  0  0.2 0  0.2 0  0  0
           .
           . 

thanks

  • 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-01T23:13:02+00:00Added an answer on June 1, 2026 at 11:13 pm

    This is one way to do it:

    a = { { 0, 0.4000, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0.2000, 0, 0.2000, 0, 0.2000, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0.2000, 0, 0, 0.2000, 0.2000 }, { 0, 0.2000, 0, 0, 0, 0, 0, 0.4000, 0, 0.2000 }};
    
    fileID = fopen('a.txt', 'at');
    
    fprintf(fileID, [ (regexprep((regexprep((regexprep((regexprep(mat2str(cell2mat(cellfun(@cell2mat, a, 'UniformOutput', false)')), '(0 )' , '$1  ')), '[', '')), ']', '')), ';', '\n')), '\n' ]);
    
    fclose(fileID);
    

    Edit: alternative solution. In this one shorter lines are padded with spaces.

    CharMatrix = char(regexprep(cellfun(@mat2str, (cellfun(@cell2mat, a, 'UniformOutput', false)'), 'UniformOutput', false), '0 ', '0   '));
    CharMatrix(CharMatrix == ']') = ' ';
    CharMatrix(:,1) = [];
    CharMatrix(:,end) = '\';
    CharMatrix(:,end+1) = 'n';
    fileID = fopen('a.txt', 'at');
    fprintf(fileID, reshape(CharMatrix', 1, []));
    fclose(fileID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related to the previous post. How to save file and read
This question is related to a previous post . Is there something comparable to
This question is related with one of my earlier questions.. Previous Post In there
This is a follow-up question related to my previous post . Below is a
Hi all I have seen all question related to this problem but couldn't find
This is related to this post . I think I am having problem with
I found this related question: How do I use composition with inheritance? I would
Original question has been answered. Update addresses related question raised in comments. Original post:
This is related to post: Server displays old version of site To repeat the
This post relates to a previous that i posted but the question is different

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.