필터 지우기
필터 지우기

Convert char to cell

조회 수: 1 (최근 30일)
António
António 2014년 12월 30일
편집: David Young 2014년 12월 30일
I want to intruduce data in a table but when i run the program it says that conversion to cell from char is not possible. Did someone knows what is wrong in this code?
ze1.Nome(end+1)=input('Introduza o seu nome: ', 's');
ze1.Aperlido(end+1)=input('Introduza o seu apelido: ','s');
ze1.Categoria(end+1)=input('Introduza a sua categoria(Aluno, Docente ou Feuncionário): ','s');
ze1.Numero(end+1)=input('Introduza o seu numero: ','s');
ze1.Mail(end+1)=input('Introduza o seu e-mail: ','s');
ze1.Telefone(end+1)=input('Introduza o seu nº de telefone: ','s');
Thank you all

채택된 답변

David Young
David Young 2014년 12월 30일
편집: David Young 2014년 12월 30일
Assuming that ze1.Nome is already a cell array, all you need to do is to replace the round brackets used for indexing it with curly brackets. This then assigns the string to the contents of a cell, rather than trying to convert the string to a cell. Like this:
ze1.Nome{end+1} = input('Introduza o seu nome: ', 's');
and the same for the other fields.
You should also consider changing the way you store the data. Instead of having a scalar struct with a cell array stored at each field, you could have a struct array with a string stored at each field. Then the line above would be
ze1(end+1).Nome = input('Introduza o seu nome: ', 's');
which may simplify some later processing. However, there will need to be changes earlier in the program to set the array up consistently with this.
  댓글 수: 1
António
António 2014년 12월 30일
Thank you!!! It really works

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 30일
ze1=struct('Nome',[],'Aperlido',[],'Categoria',[],'Numero',[],'Mail',[],'Telefone',[])
ze1.Nome{end+1}=input('Introduza o seu nome: ', 's');
ze1.Aperlido{end+1}=input('Introduza o seu apelido: ','s');
ze1.Categoria{end+1}=input('Introduza a sua categoria(Aluno, Docente ou Feuncionário): ','s');
ze1.Numero{end+1}=input('Introduza o seu numero: ','s');
ze1.Mail{end+1}=input('Introduza o seu e-mail: ','s');
ze1.Telefone{end+1}=input('Introduza o seu nº de telefone: ','s');

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by